如何在html的form提交时排除某些input field的内容

本文讲述了如何在HTML表单提交时控制哪些input字段被发送,包括使用disabled属性、移除name属性以及JavaScript操作。重点介绍了避免`<input type=password>`的隐藏策略和不推荐的删除元素方法。

在Html的form点击提交时,form内所有Input filed的内容,只要是有name属性的,并且没有disabled属性的,都会被提交,即通过网络发送到指定的URL。

如:下面的html代码显示Form内所有带有name属性的input field:

<form name="fLogin" id="fLogin" action="/cgi-bin/check_auth.json" method="post">

...

<input type="hidden" name="_lang" id="_lang" value="" disabled="">
<input type="hidden" name="frashnum" id="frashnum" value="">
<input type="hidden" name="action" id="action" value="login">
<input type="hidden" name="Frm_Logintoken" id="Frm_Logintoken" value="">
<input type="hidden" name="yourcode" id="Frm_yourcode" value="">

...

<li><input type="text" class="username" name="username" id="Frm_Username" maxlength="32" size="14"></li>

...

<li><input type="password" class="password"  id="Frm_password" name="Frm_password" maxlength="256" size="14" autocomplete="off"></li>

...

<input type="text" class="username2" name="Username2" id="Frm_Username2" maxlength="32" size="14">

...

</div></form>

用chrome打开提交Form的网页,按F12弹出开发工具窗口。在开发工具窗体选择network,输入框输入method:post,同时Preserve log(保留日志)勾选上。

 在网页点击提交,可以看到chek_auth.json, 点击它可以看到如下内容:

 

可以看到frashnum, action, Frm_Logintoken, yourcode, username, Frm_password, Username2都出现了, 说明:

(1)type="hidden" 只是在页面展示的时候隐藏,在提交的时候依然会发出;

(2)disabled="" 不影响disabled属性,其实写disabled就够了,不需要后面的赋值。

回到本文的主题,如何在form提交的时候排除某些input field。当然可以添加disabled属性。但是添加了该属性后,你是不可以在页面上对该项内容进行修改的,也就是意味着即不能输入,也不能获取focus。如果我们还是需要对它的内容进行操作呢?比方说如下的密码输入框:

它在html中的代码是:

<li><input type="password" class="password"  id="Frm_password" name="Frm_password" maxlength="256" size="14" autocomplete="off"></li>

我们只需要把name属性去掉,即:

<li><input type="password" class="password"  id="Frm_password" maxlength="256" size="14" autocomplete="off"></li>

这时候再提交Form,可以查看到发送的数据如下:

可以看到Frm_password没有了。

还有一种方法是在submit的javascript函数里,调用remove方法把这个Input field给移除

<li><input type="password" class="password"  id="Frm_password" maxlength="256" size="14" autocomplete="off"></li>
<li style="padding-top:0px;"><input type="button" class="password" id="LoginId" value="GO" onclick="doLogin()" style="width:70px;height:45px; padding:18px;"></li>

上面的html代码表示点击提交按钮GO, 对应的处理函数是doLogin()。在doLogin()里增加如下代码:

document.getElementById("Frm_password").remove();

这样的话,如果提交表单后,发生页面跳转,是不会对整个程序的正常运转带来问题的。但是如果不跳转,如本例中输入错误的密码,则该输入内容将在页面中消失,用户将无法再次输入密码。

如上图中,虽然那个对话框形势上还在,但是那是因为图片元素没有被删除。我们可以看到GO,本来是在右边的橙色框上,现在移到了左边,且框已经不能得到focus和输入了。所以,不建议使用该方法。 

 

 

 

<div class="x-column-inner" id="ext-gen100" style="width: 787px;"><div id="ext-comp-1053" class=" x-panel x-panel-noborder x-form-label-right x-column" style="width: 259px;"><div class="x-panel-bwrap" id="ext-gen102"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder" id="ext-gen103" style="width: 259px;"><div class="x-form-item " tabindex="-1" id="ext-gen117"><label for="ext-comp-1054" style="width:115px;" class="x-form-item-label" id="ext-gen118">ECO编号:</label><div class="x-form-element" id="x-form-el-ext-comp-1054" style="padding-left:120px"><input type="text" size="20" autocomplete="off" id="ext-comp-1054" name="file.fileNumber" class="x-form-text x-form-readonly x-form-field" readonly="" style="width: 126px;"></div><div class="x-form-clear-left"></div></div><div class="x-form-item " tabindex="-1" id="ext-gen119"><label for="fileStatus" style="width:115px;" class="x-form-item-label" id="ext-gen120">ECO状态:</label><div class="x-form-element" id="x-form-el-fileStatus" style="padding-left:120px"><input type="text" size="20" autocomplete="off" id="fileStatus" name="fileStatus" class="x-form-text x-form-readonly x-form-field" readonly="" style="width: 126px;"></div><div class="x-form-clear-left"></div></div><div class="x-form-item " tabindex="-1" id="ext-gen121"><label for="ext-comp-1055" style="width:115px;" class="x-form-item-label" id="ext-gen122">申请人电话<font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-ext-comp-1055" style="padding-left:120px"><input type="text" size="20" autocomplete="off" id="ext-comp-1055" name="file.requesterNumber" class="x-form-text x-form-field x-form-readonly" style="width: 126px;" readonly=""></div><div class="x-form-clear-left"></div></div><div class="x-form-item " tabindex="-1" id="ext-gen123"><label for="ext-comp-1056" style="width:115px;" class="x-form-item-label" id="ext-gen124"><font color="blue" style="background:yellow;">是否研发设计责任</font><font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-ext-comp-1056" style="padding-left:120px"><div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen125" style="width: 126px;"><input type="hidden" name="file.isRdResp" id="ext-gen127" value="否"><input type="text" size="24" autocomplete="off" id="ext-comp-1056" class="x-form-text x-form-field x-trigger-noedit x-form-readonly" readonly="" style="width: 126px;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="" class="x-form-trigger x-form-arrow-trigger" id="ext-gen126" style="display: none;"></div></div><div class="x-form-clear-left"></div></div><div class="x-form-item " tabindex="-1" id="ext-gen128"><label for="ext-comp-1057" style="width:115px;" class="x-form-item-label" id="ext-gen129">更改阶段<font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-ext-comp-1057" style="padding-left:120px"><div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen130" style="width: 126px;"><input type="hidden" name="file.changeStage" id="ext-gen132" value="设计"><input type="text" size="24" autocomplete="off" id="ext-comp-1057" class="x-form-text x-form-field x-trigger-noedit x-form-readonly" readonly="" style="width: 126px;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="" class="x-form-trigger x-form-arrow-trigger" id="ext-gen131" style="display: none;"></div></div><div class="x-form-clear-left"></div></div></div></div></div><div id="ext-comp-1058" class=" x-panel x-panel-noborder x-form-label-right x-column" style="width: 259px;"><div class="x-panel-bwrap" id="ext-gen105"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder" id="ext-gen106" style="width: 259px;"><div class="x-form-item " tabindex="-1" id="ext-gen133"><label for="ext-gen11" style="width:110px;" class="x-form-item-label" id="ext-gen134">申请人<font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-ext-gen11" style="padding-left:115px"><div class="x-form-field-wrap x-form-file-wrap" id="ext-gen135" style="width: 131px;"><input type="text" size="20" autocomplete="off" id="ext-gen11" class="x-form-text x-form-readonly x-form-field x-form-file-text" readonly="" style="width: 96px;"><table id="ext-comp-1180" cellspacing="0" class="x-btn x-form-file-btn x-btn-noicon x-item-disabled" style="width: auto;"><tbody class="x-btn-small x-btn-icon-small-left"><tr><td class="x-btn-tl"><i> </i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i> </i></td></tr><tr><td class="x-btn-ml"><i> </i></td><td class="x-btn-mc"><em class="" unselectable="on"><button type="button" id="ext-gen136" class=" x-btn-text">选择</button></em></td><td class="x-btn-mr"><i> </i></td></tr><tr><td class="x-btn-bl"><i> </i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i> </i></td></tr></tbody></table><input type="hidden" size="20" autocomplete="off" id="ext-comp-1181" name="file.requestMemberId" class=" x-form-hidden x-form-field" value="15388"></div></div><div class="x-form-clear-left"></div></div><div class="x-form-item " tabindex="-1" id="ext-gen137"><label for="implementDate" style="width:110px;" class="x-form-item-label" id="ext-gen138">实施日期:</label><div class="x-form-element" id="x-form-el-implementDate" style="padding-left:115px"><input type="text" size="20" autocomplete="off" id="implementDate" name="implementDate" class="x-form-text x-form-readonly x-form-field" readonly="" style="width: 131px;"></div><div class="x-form-clear-left"></div></div><div class="x-form-item " tabindex="-1" id="ext-gen139"><label for="hasOther" style="width:110px;" class="x-form-item-label" id="ext-gen140">多人合作ECO<font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-hasOther" style="padding-left:115px"><div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen141" style="width: 131px;"><input type="hidden" name="file.hasOther" id="ext-gen143" value="是"><input type="text" size="24" autocomplete="off" id="hasOther" class="x-form-text x-form-field x-trigger-noedit x-form-readonly" readonly="" style="width: 131px;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="" class="x-form-trigger x-form-arrow-trigger" id="ext-gen142" style="display: none;"></div></div><div class="x-form-clear-left"></div></div><div class="x-form-item" tabindex="-1" id="ext-gen144"><label for="df2" style="width:110px;" class="x-form-item-label" id="ext-gen145"></label><div class="x-form-element" id="x-form-el-df2" style="padding-left:115px"><div id="df2" name="df2" class="x-form-display-field" style="height: 20px; width: 131px;"></div></div><div class="x-form-clear-left"></div></div><div class="x-form-item x-hide-display" tabindex="-1" id="ext-gen146"><label for="ext-comp-1059" style="width:110px;" class="x-form-item-label" id="ext-gen147">责任部门:</label><div class="x-form-element" id="x-form-el-ext-comp-1059" style="padding-left:115px"><input type="text" size="20" autocomplete="off" id="ext-comp-1059" name="file.respDep" class="x-form-text x-form-field x-hide-display x-item-disabled x-form-readonly" style="width: 131px;" disabled="" readonly=""></div><div class="x-form-clear-left"></div></div><div class="x-form-item " tabindex="-1" id="ext-gen148"><label for="ecoDep" style="width:110px;" class="x-form-item-label" id="ext-gen149">ECO部门<font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-ecoDep" style="padding-left:115px"><div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen150" style="width: 131px;"><input type="hidden" name="file.ecoDep" id="ext-gen152" value="研发"><input type="text" size="24" autocomplete="off" id="ecoDep" class="x-form-text x-form-field x-trigger-noedit x-form-readonly" readonly="" style="width: 131px;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="" class="x-form-trigger x-form-arrow-trigger" id="ext-gen151" style="display: none;"></div></div><div class="x-form-clear-left"></div></div></div></div></div><div id="ext-comp-1060" class=" x-panel x-panel-noborder x-form-label-right x-column" style="width: 267px;"><div class="x-panel-bwrap" id="ext-gen108"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder" id="ext-gen109" style="width: 267px;"><div class="x-form-item " tabindex="-1" id="ext-gen153"><label for="creationDate" style="width:100px;" class="x-form-item-label" id="ext-gen154">填表日期:</label><div class="x-form-element" id="x-form-el-creationDate" style="padding-left:105px"><input type="text" size="20" autocomplete="off" id="creationDate" name="creationDate" class="x-form-text x-form-readonly x-form-field" readonly="" style="width: 148px;"></div><div class="x-form-clear-left"></div></div><div class="x-form-item " tabindex="-1" id="ext-gen155"><label for="releaseDate" style="width:100px;" class="x-form-item-label" id="ext-gen156">发布日期:</label><div class="x-form-element" id="x-form-el-releaseDate" style="padding-left:105px"><input type="text" size="20" autocomplete="off" id="releaseDate" name="releaseDate" class="x-form-text x-form-readonly x-form-field" readonly="" style="width: 148px;"></div><div class="x-form-clear-left"></div></div><div class="x-form-item x-hide-display" tabindex="-1" id="ext-gen157"><label for="df" style="width:100px;" class="x-form-item-label" id="ext-gen158"></label><div class="x-form-element" id="x-form-el-df" style="padding-left:105px"><div id="df" name="df" class=" x-form-display-field x-hide-display" style="height: 20px; width: 148px;"></div></div><div class="x-form-clear-left"></div></div><div class="x-form-item" tabindex="-1" id="ext-gen159"><label for="ext-comp-1061" style="width:100px;" class="x-form-item-label" id="ext-gen160">合作申请人<font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-ext-comp-1061" style="padding-left:105px"><div class="x-form-field-wrap x-form-file-wrap" id="ext-gen161" style="width: 148px;"><input type="text" size="20" autocomplete="off" id="ext-comp-1061" class="x-form-text x-form-readonly x-form-field x-form-file-text" readonly="" style="width: 113px;"><table id="ext-comp-1182" cellspacing="0" class="x-btn x-form-file-btn x-btn-noicon x-item-disabled" style="width: auto;"><tbody class="x-btn-small x-btn-icon-small-left"><tr><td class="x-btn-tl"><i> </i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i> </i></td></tr><tr><td class="x-btn-ml"><i> </i></td><td class="x-btn-mc"><em class="" unselectable="on"><button type="button" id="ext-gen162" class=" x-btn-text">选择</button></em></td><td class="x-btn-mr"><i> </i></td></tr><tr><td class="x-btn-bl"><i> </i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i> </i></td></tr></tbody></table><input type="hidden" size="20" autocomplete="off" id="ext-comp-1183" name="file.otherMakerIds" class="x-form-hidden x-form-field" value="9612,14211"></div></div><div class="x-form-clear-left"></div></div><input type="hidden" size="20" autocomplete="off" id="ext-comp-1062" name="file.otherMakerNames" class=" x-form-hidden x-form-field" value="涂涛,修晨宇"><div class="x-form-item" tabindex="-1" id="ext-gen163"><label for="df3" style="width:100px;" class="x-form-item-label" id="ext-gen164"></label><div class="x-form-element" id="x-form-el-df3" style="padding-left:105px"><div id="df3" name="df3" class="x-form-display-field" style="height: 20px; width: 148px;"></div></div><div class="x-form-clear-left"></div></div><div class="x-form-item x-hide-display" tabindex="-1" id="ext-gen165"><label for="ext-comp-1063" style="width:100px;" class="x-form-item-label" id="ext-gen166">责任部门审核:</label><div class="x-form-element" id="x-form-el-ext-comp-1063" style="padding-left:105px"><div class="x-form-field-wrap x-form-file-wrap" id="ext-gen167" style="width: 148px;"><input type="text" size="20" autocomplete="off" id="ext-comp-1063" class="x-form-text x-form-readonly x-form-field x-form-file-text x-hide-display x-item-disabled" readonly="" style="width: 0px;" disabled=""><table id="ext-comp-1184" cellspacing="0" class="x-btn x-form-file-btn x-btn-noicon x-item-disabled" style="width: auto;"><tbody class="x-btn-small x-btn-icon-small-left"><tr><td class="x-btn-tl"><i> </i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i> </i></td></tr><tr><td class="x-btn-ml"><i> </i></td><td class="x-btn-mc"><em class="" unselectable="on"><button type="button" id="ext-gen168" class=" x-btn-text">选择</button></em></td><td class="x-btn-mr"><i> </i></td></tr><tr><td class="x-btn-bl"><i> </i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i> </i></td></tr></tbody></table><input type="hidden" size="20" autocomplete="off" id="ext-comp-1185" name="file.respApId" class=" x-form-hidden x-form-field x-item-disabled" value="" disabled=""></div></div><div class="x-form-clear-left"></div></div><div id="ext-comp-1064" class=" x-panel x-panel-noborder" style="width: 267px;"><div class="x-panel-bwrap" id="ext-gen169"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder x-column-layout-ct" id="ext-gen170" style="width: 267px;"><div class="x-column-inner" id="ext-gen172" style="width: 267px;"><div id="ext-comp-1065" class=" x-panel x-panel-noborder x-form-label-right x-column" style="width: 133px;"><div class="x-panel-bwrap" id="ext-gen174"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder" id="ext-gen175" style="width: 133px;"><div class="x-form-item " tabindex="-1" id="ext-gen180"><label for="org" style="width:100px;" class="x-form-item-label" id="ext-gen181">涉及组织<font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-org" style="padding-left:105px"><div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen182" style="width: 21px;"><input type="hidden" name="file.org" id="ext-gen184" value="LZ2"><input type="text" size="24" autocomplete="off" id="org" class="x-form-text x-form-field x-trigger-noedit x-form-readonly" readonly="" style="width: 21px;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="" class="x-form-trigger x-form-arrow-trigger" id="ext-gen183" style="display: none;"></div></div><div class="x-form-clear-left"></div></div></div></div></div><div id="ext-comp-1066" class=" x-panel x-panel-noborder x-form-label-right x-column" style="width: 133px;"><div class="x-panel-bwrap" id="ext-gen177"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder" id="ext-gen178" style="width: 133px;"><div class="x-form-item x-hide-display" tabindex="-1" id="ext-gen185"><label for="ext-comp-1067" style="width:100px;" class="x-form-item-label" id="ext-gen186">代工组织:</label><div class="x-form-element" id="x-form-el-ext-comp-1067" style="padding-left:105px"><input type="text" size="20" autocomplete="off" id="ext-comp-1067" name="file.oemOrg" class="x-form-text x-form-readonly x-form-field x-hide-display" readonly=""></div><div class="x-form-clear-left"></div></div></div></div></div><div class="x-clear" id="ext-gen173"></div></div></div></div></div><input type="hidden" size="20" autocomplete="off" id="needProd" name="needProd" class=" x-form-hidden x-form-field" value="是"></div></div></div><div id="ext-comp-1068" class=" x-panel x-panel-noborder x-column" style="width: 787px;"><div class="x-panel-bwrap" id="ext-gen111"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder x-column-layout-ct" id="ext-gen112" style="width: 787px;"><div class="x-column-inner" id="ext-gen187" style="width: 787px;"><div id="ext-comp-1069" class=" x-panel x-panel-noborder x-form-label-right x-column" style="width: 259px;"><div class="x-panel-bwrap" id="ext-gen189"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder" id="ext-gen190" style="width: 259px;"><div class="x-form-item " tabindex="-1" id="ext-gen195"><label for="changeType" style="width:115px;" class="x-form-item-label" id="ext-gen196">更改类型<font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-changeType" style="padding-left:120px"><div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen197" style="width: 126px;"><input type="hidden" name="file.changeType" id="ext-gen199" value="软件更改(涉及组代)"><input type="text" size="24" autocomplete="off" id="changeType" class="x-form-text x-form-field x-trigger-noedit x-form-readonly" readonly="" style="width: 126px;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="" class="x-form-trigger x-form-arrow-trigger" id="ext-gen198" style="display: none;"></div></div><div class="x-form-clear-left"></div></div><div class="x-form-item" tabindex="-1" id="ext-gen200"><label for="involveHardware" style="width:115px;" class="x-form-item-label" id="ext-gen201">是否涉及硬件<span style="border:1px solid;border-radius:50%;color:blue;text-align:center;"> ? </span><font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-involveHardware" style="padding-left:120px"><div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen202" style="width: 126px;"><input type="hidden" name="file.involveHardware" id="ext-gen204" value="涉及"><input type="text" size="24" autocomplete="off" id="involveHardware" class="x-form-text x-form-field x-trigger-noedit x-form-readonly" readonly="" style="width: 126px;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="" class="x-form-trigger x-form-arrow-trigger" id="ext-gen203" style="display: none;"></div></div><div class="x-form-clear-left"></div></div></div></div></div><div id="ext-comp-1070" class=" x-panel x-panel-noborder x-form-label-right x-column" style="width: 519px;"><div class="x-panel-bwrap" id="ext-gen192"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder" id="ext-gen193" style="width: 519px;"><div class="x-form-item " tabindex="-1" id="ext-gen205"><label for="ext-comp-1071" style="width:110px;" class="x-form-item-label" id="ext-gen206">题目<font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-ext-comp-1071" style="padding-left:115px"><input type="text" size="20" autocomplete="off" id="ext-comp-1071" name="file.title" class="x-form-text x-form-field x-form-readonly" style="width: 396px;" readonly=""></div><div class="x-form-clear-left"></div></div></div></div></div><div class="x-clear" id="ext-gen188"></div></div></div></div></div><div id="ext-comp-1072" class=" x-panel x-panel-noborder x-column" style="width: 787px;"><div class="x-panel-bwrap" id="ext-gen114"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder x-column-layout-ct" id="ext-gen115" style="width: 787px;"><div class="x-column-inner" id="ext-gen207" style="width: 787px;"><div id="ext-comp-1073" class=" x-panel x-panel-noborder x-form-label-right x-column" style="width: 259px;"><div class="x-panel-bwrap" id="ext-gen209"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder" id="ext-gen210" style="width: 259px;"><div class="x-form-item " tabindex="-1" id="ext-gen215"><label for="ext-comp-1074" style="width:115px;" class="x-form-item-label" id="ext-gen216">是否对返修品有效<font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-ext-comp-1074" style="padding-left:120px"><div class="x-form-field-wrap x-form-field-trigger-wrap" id="ext-gen217" style="width: 126px;"><input type="hidden" name="file.effectReturn" id="ext-gen219" value="否"><input type="text" size="24" autocomplete="off" id="ext-comp-1074" class="x-form-text x-form-field x-trigger-noedit x-form-readonly" readonly="" style="width: 126px;"><img src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="" class="x-form-trigger x-form-arrow-trigger" id="ext-gen218" style="display: none;"></div></div><div class="x-form-clear-left"></div></div></div></div></div><div id="ext-comp-1075" class=" x-panel x-panel-noborder x-form-label-right x-column" style="width: 519px;"><div class="x-panel-bwrap" id="ext-gen212"><div class="x-panel-body x-panel-body-noheader x-panel-body-noborder" id="ext-gen213" style="width: 519px;"><div class="x-form-item x-hide-display" tabindex="-1" id="ext-gen220"><label for="ext-comp-1078" style="width:110px;" class="x-form-item-label" id="ext-gen221">有效范围:</label><div class="x-form-element" id="x-form-el-ext-comp-1076" style="padding-left:115px"><div id="ext-comp-1077" class=" x-form-composite x-box-layout-ct x-form-field x-hide-display" style="width: 389px;"><div class="x-box-inner" id="ext-gen223" style=""><div class="x-form-check-wrap x-box-item" id="ext-gen224" style="width: 115px; left: 0px; top: 0px;"><input type="checkbox" autocomplete="off" id="ext-comp-1078" name="file.effectRange" class=" x-form-checkbox x-form-field x-form-readonly" value="Y" checked="" readonly=""><label for="ext-comp-1078" class="x-form-cb-label" id="ext-gen225"> </label></div></div></div></div><div class="x-form-clear-left"></div></div><div class="x-form-item " tabindex="-1" id="ext-gen226"><label for="ext-comp-1079" style="width:110px;" class="x-form-item-label" id="ext-gen227">对以下机型有效<font color="red">*</font>:</label><div class="x-form-element" id="x-form-el-ext-comp-1079" style="padding-left:115px"><input type="text" size="20" autocomplete="off" id="ext-comp-1079" name="file.itemModel" class="x-form-text x-form-field x-form-readonly" style="width: 396px;" readonly=""></div><div class="x-form-clear-left"></div></div></div></div></div><div class="x-clear" id="ext-gen208"></div></div></div></div></div><div class="x-clear" id="ext-gen101"></div></div>如上是一段html代码,我有很多这样的片段。我要你从完整html页面中找出这些对,如ext-comp-1056中"是否研发设计责任"对应“是”。使用playwright,最后保存到文本中
最新发布
11-04
function validateForm(formId, fields) { var errorMsg = ""; // 校验静态字段 fields.forEach(function (field) { var selector; if (field.type === "select") { selector = $("#" + formId + " select[name='" + field.name + "']"); } else { selector = $("#" + formId + " input[name='" + field.name + "']"); } var value = selector.val().trim(); if (field.editable === false && formId != "frmEnter") return; if (field.required && value === "") { errorMsg += "「" + field.label + "」能为空,请输入有效值。\n"; } }); // 校验动态生成的 BIN 字段 $("#" + formId + " input[name]").each(function () { var name = $(this).attr("name"); // 排除静态字段 var isStaticField = fields.some(function (field) { return field.name === name; }); if (isStaticField) return; var value = $(this).val().trim(); var maxQty = window.selectedBinData[name] || 0; if (value === "") { errorMsg += "「" + name + "」能为空,请输入有效值。\n"; } else if (!/^\d+$/.test(value)) { errorMsg += "「" + name + "」必须为非负整数。\n"; } else if (parseInt(value) > maxQty) { errorMsg += "「" + name + "」输入数量能大于当前数量:" + maxQty + "。\n"; } }); if (errorMsg !== "") { alert("存在未填写项:\n" + errorMsg); return false; } // 如果是 Update 表单,则显示二次确认信息 if (formId === 'frmUpdate') { var beforeText = "Update前 Bin信息:\n"; var afterText = "Update后 Bin信息:\n"; var hasBinData = false; $("#" + formId + " input[name]").each(function () { var name = $(this).attr("name"); var isStaticField = fields.some(function (field) { return field.name === name; }); if (isStaticField) return; var beforeQty = window.selectedBinData[name] || 0; var afterQty = $(this).val().trim(); if (afterQty === "") return; beforeText += name + ":" + beforeQty + "\n"; afterText += name + ":" + afterQty + "\n"; hasBinData = true; }); if (hasBinData) { var confirmMsg = beforeText + "\n" + afterText + "\n确认提交吗?"; if (!confirm(confirmMsg)) { return false; } } } return true; }这样的
09-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值