1,入坑記錄
不知道第幾次入坑這個button的type屬性了,今天我要記錄一下,告誡一下自己。經常你回發現正確的jquery語句,但是點擊事件卻沒有反應,如果你不調試,你可能發現不了問題,其實效果已經出來了,但是頁面刷新了,導致跟沒效果一樣。
2,代碼演示(錯誤)
<html>
<head>
<title>Insert title here</title>
<script src="https://cdn.bootcss.com/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("#add").click(function(){
$("#add").attr('disabled',true);
$("#add").text('已發送');
$("#br").before("驗證碼: <input type='text' name='checkcode'/>");
});
});
</script>
</head>
<body>
<form action="#" method="post">
手機號: <input type="text" name="phone"><button id="add"> 發送驗證碼</button>
<br>
<br id="br">
</form>
</body>
</html>
####3,代碼演示(正確)
<html>
<head>
<title>Insert title here</title>
<script src="https://cdn.bootcss.com/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("#add").click(function(){
$("#add").attr('disabled',true);
$("#add").text('已發送');
$("#br").before("驗證碼: <input type='text' name='checkcode'/>");
});
});
</script>
</head>
<body>
<form action="#" method="post">
手機號: <input type="text" name="phone"><button type="button" id="add"> 發送驗證碼</button>
<br>
<br id="br">
</form>
</body>
</html>