jquery練習2筆記

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 var fields = $("#fm").serializeArray();
jQuery.each( fields, function(i, field){
 $("#results").append(field.value + " ");
});$("#fm").change(function(){ fields = $("#fm").serializeArray();$("#results").text("");
jQuery.each( fields, function(i, field){
 $("#results").append(field.value + " ");
});
 
});
});
</script>
</head>
<body>
<p id="results"><b>Results:</b> </p>
<form id="fm">
 <select name="single">
    <option>Single</option>
    <option>Single2</option>
 </select>
 <select name="multiple" multiple="multiple">
    <option selected="selected">Multiple</option>
    <option>Multiple2</option>
    <option selected="selected">Multiple3</option>
 </select><br/>
 <input type="checkbox" name="check" value="check1" checked="checked"/> check1
 <input type="checkbox" name="check" value="check2" /> check2
 <input type="radio" name="radio" value="radio1" checked="checked"/> radio1
 <input type="radio" name="radio" value="radio2"/> radio2
</form>
</body>
</html>
 
1、 change事件
2、 append 增加
3
var fields = $("#fm").serializeArray();
jQuery.each( fields, function(i, field){
 $("#results").append(field.value + " ");
}); 遍歷每個控件值
作者“技術學習筆記”

發佈留言