找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 468|回复: 0

[js/jquery基础] jquery监听div、input、textarea内容变化

[复制链接]
发表于 2023-4-28 21:31 | 显示全部楼层 |阅读模式

第一种:change事件

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

$("#demo").bind("change", function(){
    alert('a');
});

第一种:DOMNodeInserted事件(插入事件)、DOMNodeInserted事件(移除事件)

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

textarea监听内容变化

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

 

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|学习笔记

GMT+8, 2024-9-8 09:58 , Processed in 0.026905 second(s), 13 queries , APCu On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表