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 表單驗證插件
9.表單提交前進驗證 (可以使用form表單的onsubmit方法);
<HTML> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <BODY> <form action="http://www.baidu.com" onsubmit="return toVaild()"> <input type="text" id="ff"> <input type="submit" id="submit" value ="提交"/> </form> </BODY> <script language="javascript"> function toVaild(){ var val = document.getElementById("ff").value; alert(val); if(val == "可以提交"){ alert("校驗成功,之后進行提交"); return true; } else{ alert("校驗失敗,不進行提交"); return false; } } </script> </HTML>
10. 獲取表單數據 $("form").serialize(); 例:FirstName=Bill&LastName=Gates
11.圖片轉為 base64 編碼顯示 (webpack打包)
.index {
background:
if(undefined){
console.log('undefined是true')
}else{
console.log('undefined是false') // 執行這里,undefined為false
}
