1. 程式人生 > >利用jQuery選擇器快速匹配文檔中的按鈕,並為該按鈕綁定事件處理函數

利用jQuery選擇器快速匹配文檔中的按鈕,並為該按鈕綁定事件處理函數

body var jquery pla .org title color button ansi

技術分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jQuery/版本號自己選"></script>
<script type="text/javascript">
$(
function(){ $(‘input[type="button"]‘).click(function(){ var i = 0; $(‘input[type="text"]‘).each(function(){ i += parseInt($(this).val()); }); $("label").text(i); }); $(‘input:lt(2)‘) .add("label") .css({ ‘border‘:‘none‘,
‘textAlign‘:‘center‘, ‘borderBottom‘:‘solid 1px navy‘, ‘width‘:‘30px‘ }); }); </script> <title>上機練習</title> </head> <body> <input type="text" value="" />+ <input type="text" value="" /> <input type="button" value="=" /> <label></label> </body> </html>
View Code

技術分享

利用jQuery選擇器快速匹配文檔中的按鈕,並為該按鈕綁定事件處理函數