我生产从我的PHP code多种形式,如下图所示。
问题是,如果我想执行的jQuery Ajax请求,如何我指的是一种形式。我的目标是,在点击提交按钮时,从该表单的相关数据应张贴。
previously,我指的是形成其 $('#身份证')。提交()
功能。但是,我在这里停留,因为所有的形式具有相同的名称。
<形式ID =视图文档的方法=邮报的目标=报告行动=../类/ openDoc.php>
<输入类型=隐藏ID =IDNAME =ID值=1/>
<输入类型=隐藏ID =文件名NAME =文件名值=研究报告的作者测试8.doc/>
<输入类型=隐藏ID =文件类型NAME =文件类型值=文档/>
< TD><输入类型=提交级=S-按钮btn_normalID =提交值=查看的onsubmit =的window.open(约:空白,报表,宽度= 300,高度= 200 )/>
< /形式GT;
<形式ID =视图文档的方法=邮报的目标=报告行动=../类/ openDoc.php>
<输入类型=隐藏ID =IDNAME =ID值=2/>
<输入类型=隐藏ID =文件名NAME =文件名值=模板[1] .IEEEdoc.doc/>
<输入类型=隐藏ID =文件类型NAME =文件类型值=文档/>
<输入类型=提交级=S-按钮btn_normalID =提交值=查看的onsubmit =的window.open(约:空白,报表,宽度= 300,高度= 200)/&GT ;
< /形式GT;
<形式ID =视图文档的方法=邮报的目标=报告行动=../类/ openDoc.php>
<输入类型=隐藏ID =IDNAME =ID值=3/>
<输入类型=隐藏ID =文件名NAME =文件名值=作业#3.docx/>
<输入类型=隐藏ID =文件类型NAME =文件类型值=OCX/>
<输入类型=提交级=S-按钮btn_normalID =提交值=查看的onsubmit =的window.open(约:空白,报表,宽度= 300,高度= 200)/&GT ;
< /形式GT;
解决方案
ID
属性必须是唯一的。如果可能的话,请考虑视图-DOC-1
,视图-DOC-2
和查看 - DOC-3
的形式 ID
。
否则,使用类
而不是 ID
键,这样做对JavaScript的:
$(视图文档输入[类型=提交]绑定(点击,函数(){
//当按钮点击您的code。解雇了所有的3个按钮
});
I am producing multiple forms from my php code as shown below.
The problem is that, If I want to perform a jquery-ajax request, How can I refer to a form. My goal is that when the submit button is clicked, the relevant data from that form should be posted.
Previously, I was referring to form with its $('#id').submit()
function. But I am stuck here since all of the forms have the same name.
<form id="view-doc" method="post" target="report" action="../classes/openDoc.php">
<input type="hidden" id="id" name="id" value="1"/>
<input type="hidden" id="filename" name="filename" value="Research Writer Test 8.doc" />
<input type="hidden" id="filetype" name="filetype" value="doc" />
<td><input type="submit" class="s-button btn_normal" id="submit" value="View" onsubmit="window.open(about:blank,report,width=300,height=200)" />
</form>
<form id="view-doc" method="post" target="report" action="../classes/openDoc.php">
<input type="hidden" id="id" name="id" value="2"/>
<input type="hidden" id="filename" name="filename" value="template[1].IEEEdoc.doc" />
<input type="hidden" id="filetype" name="filetype" value="doc" />
<input type="submit" class="s-button btn_normal" id="submit" value="View" onsubmit="window.open(about:blank,report,width=300,height=200)" />
</form>
<form id="view-doc" method="post" target="report" action="../classes/openDoc.php">
<input type="hidden" id="id" name="id" value="3"/>
<input type="hidden" id="filename" name="filename" value="Assignment #3.docx" />
<input type="hidden" id="filetype" name="filetype" value="ocx" />
<input type="submit" class="s-button btn_normal" id="submit" value="View" onsubmit="window.open(about:blank,report,width=300,height=200)" />
</form>
解决方案
id
attribute has to be unique. If possible please consider view-doc-1
, view-doc-2
and view-doc-3
for the forms' id
.
Otherwise, use class
instead of id
and do this on JavaScript:
$(".view-doc input[type=submit]".bind('click', function() {
// your code when button clicked. fired on all the 3 buttons
});