[英]Differentiate between field on background page and on form through JavaScript?
我需要通过JavaScript区分两个字段(命名为ABC)。 我有一个主页,字段ABC出现在该主页上,然后我有一个表格(添加了新内容的对话框)出现在该主页的顶部。 现在,表格也具有字段ABC。
我想对表单上的字段进行处理,但是javaScipt会继续在后台页面上提取字段。
请任何可以帮助的人? 提前谢谢了。
将数据属性添加到字段或表单。
的HTML
<form data-which-form="main">
<input type="text"name="abc">
<input type="submit">
</form>
<form data-which-form="popup">
<input type="text"name="abc">
<input type="submit">
</form>
JS
$(document).on('submit','form',function(e){
if($(this).data('which-form')=='main'){
var mainAbc = $(this).find('input[name=abc]');
}
//do stuff
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.