1.动态生成的DOM做点击事件无效 https://blog.csdn.net/mm_hello11/article/details/79010679
2.消除button的默认样式
margin: 0;padding: 0;border: 1px solid transparent; //自定义边框outline: none; //消除默认点击蓝色边框效果
3. 键盘按下事件
$("#btn").keydown(function(event){ if(event.keyCode == 13){ alert(‘你按下了Enter‘); }});
4.on事件
1. $("#JS_ul").off("click").on("click","li",function(event){ ???????????????????????var val = $(this).html() ???????$("#JS_ul li").removeClass("yactive"); ???????$(this).addClass(‘yactive‘); ?
});
2. $("p").on("click",function(){ alert("段落被点击了。"); });
3. $("div").on("click","p",function(){ ???alert($(this).text()); })
5.字符串拼接
for (var i = 0; i <= obj.length-1; i++) { ?????html += ‘<li id="JS_li">‘+ ??????????????????????‘<div class="box">‘+ ??????????????????????‘<div class="y_num">‘+obj[i].code+‘</div><div class="y_town">‘+obj[i].name+‘</div>‘+ ??????????????????????‘</div>‘+ ?????????????‘</li>‘}$(‘#JS_ul‘).html(html);
6.input 框禁止编辑 readonly="readonly"
7. ??json格式转换
var json = ‘{"result":true, "count":42}‘;var obj = JSON.parse(json);var foo = {foundation: "Mozilla", model: "box", week: 45, transport: "car", month: 7};var jsonString = JSON.stringify(foo, replacer);
8. validform.js 表单验证插件
js,css随笔(动态生成的dom做点击事件无效)
原文地址:https://www.cnblogs.com/ygyy/p/9993795.html