javascript - jquery-delegate()绑定元素出现重复?

WBOY
Release: 2016-06-06 20:17:04
Original
1283 people have browsed it

如题,我用delegate()绑定了input text框(name=exp[]),出现多个,该如何去除重复呢?
HTML

<code><div class="col-sm-4">
   = Html::textInput('ruleexp[]','',['class'=>'form-control','required'=>'required']) ?>
</div> </code>
Copy after login
Copy after login

js

<code>$('div').delegate('input[name="ruleexp[]"]','blur',function(){
    //code
});</code>
Copy after login
Copy after login

还有就是某些input text框我是动态加上去的,这也是我采用delegate()绑定的原因。
重复的后果就是:我打印出这个input的值,结果出现了多个。。

javascript - jquery-delegate()绑定元素出现重复?

回复内容:

如题,我用delegate()绑定了input text框(name=exp[]),出现多个,该如何去除重复呢?
HTML

<code><div class="col-sm-4">
   = Html::textInput('ruleexp[]','',['class'=>'form-control','required'=>'required']) ?>
</div> </code>
Copy after login
Copy after login

js

<code>$('div').delegate('input[name="ruleexp[]"]','blur',function(){
    //code
});</code>
Copy after login
Copy after login

还有就是某些input text框我是动态加上去的,这也是我采用delegate()绑定的原因。
重复的后果就是:我打印出这个input的值,结果出现了多个。。

javascript - jquery-delegate()绑定元素出现重复?

<code>$('div').undelegate().delegate('input[name="ruleexp[]"]','blur',function(){
    //code
});

试试看。</code>
Copy after login

delegate()换成on()吧,另外,你的描述不太清楚,是只有一个'input[name="ruleexp[]"]',你的结果出来了多个,还是因为本来有多个,你想筛选出一个?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template