杰克工作室 发表于 2023-4-28 21:31

jquery监听div、input、textarea内容变化

<p><strong>第一种:change事件</strong></p>

<p>change事件在元素的值发生变化时触发,适用于input、textarea、select</p>

<pre>
$(&quot;#demo&quot;).bind(&quot;change&quot;, function(){
    alert(&#39;a&#39;);
});</pre>

<p><strong>第一种:DOMNodeInserted事件</strong>(插入事件)、<strong>DOMNodeInserted事件</strong>(移除事件)</p>

<pre>
DOMNodeInserted事件只有在插入节点时有效,相反DOMNodeRemoved事件,只有在移除节点时有效。
$(&#39;#demo&#39;).bind(&#39;DOMNodeInserted&#39;, function() {
   alert(&#39;a&#39;)
})
$(&#39;#demo&#39;).bind(&#39;DOMNodeRemoved&#39;, function() {
   alert(&#39;b&#39;)
})</pre>

<p>textarea监听内容变化</p>

<pre>
$(&#39;#sendtxt&#39;).bind(&#39;input propertychange&#39;,&#39;textarea&#39;,function(){
  //#sendtxt为textarea的id
    var curLength=$(this).val();
    if(curLength == &#39;&#39;) $(&#39;.foot_add&#39;).show(); else $(&#39;.foot_add&#39;).hide();
});</pre>

<p>&nbsp;</p>
页: [1]
查看完整版本: jquery监听div、input、textarea内容变化