Jquery動態添加元素添加綁定事件javascript
Jquery append 等動態添加元素不能直接綁定事件,須要使用on,例如html
<html> <head> <script type="text/javascript" src="jquery-1.11.0.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#add").click(function(){ $("#main").append('<input type="text" value="" name="a2" class="a2" />'); }); $(document).on("change",".a2",function(e){ alert($(this).val()); }); }); </script> </head> <body> <div id="main" style="width:300px; height:100px;border:1px solid red"> </div> <input type="button" value="添加" id="add" /> </body> </html>
獲取高度寬度java
http://code.jquery.com/jquery-1.4.1.js
jquery
$(window).height() -- 獲取瀏覽器當前窗口可視區域高度瀏覽器
$(document).height() -- 獲取瀏覽器當前窗口文檔高度閉包
$(document.body).height() -- 獲取瀏覽器當前窗口文檔body的高度app
$(document.body).outerHeight(true) -- 獲取瀏覽器當前窗口可視區域寬度this
獲取select標籤值和文本spa
$("#pcode option:selected").val() -- 獲取選擇值code
$("#pcode option:selected").text() -- 獲取選擇文本
判斷字符串空
if(yj == null || yj == undefined || yj == ''){}
jquery閉包
(function($){
})(jQuery);
阻止表單提交
$("#_form1").submit(function(e){
e.preventDefault();
alert("表單阻止提交了");
});
驗證表單後提交
$("#_form1").submit(function(){
if(須要提交時){
$("button[type=submit]").attr("disabled","true"); -- 避免重複提交
return true;
}else(不須要提交時){
return false;
}
});