checkbox:
<input type="checkbox" name="vehicle" value="Bike">I have a bike</input>
<input type="checkbox" name="vehicle" value="Car">I have a car:</input>
<input type="checkbox" name="vehicle" value="Airplane">I have an airplane:</input>
<button class="btn1">Hide Checkboxes</button>
//引入jquery.js
$('.btn1').click(function(){
var value=[]
$(':checkbox:checked').each(function(index,item){
//value.push(index.value);
value.push($(this).val());//建议使用该方法
})
})
jquery:
attr:获取选择器中某个属性的值
<input id="testId" name="testName" type="text" style="color:red" value="testValue"/>
<script>
console.log($('input[name=testName]').attr("style");
</script>
attr:修改某个或部分属性的值
<script>
$(document).ready(function(){
$("button").click(function(){
$("#w3s").attr({
"href" : "http://www.w3school.com.cn/jquery/",
"title" : "W3School jQuery 教程"
});
alert($("#w3s").attr("href"));
});
});
</script>
</head>
<body>
<p><a href="http://www.w3school.com.cn" id="w3s">W3School.com.cn</a></p>
<button>改变 href 和 title 值</button>
<p>请把鼠标指针移动到链接上,或者点击该链接,来查看已经改变的 href 值和已经设置的 title 值。</p>
</body>
</html>
text()、html()、val()、attr() 回调函数(回调函数由两个参数:被选元素列表中当前元素的下标,以及原始(旧的)值。然后以函数新值返回您希望使用的字符串)
<input id="testId" value="oldValue"/>
<script>
$('#testId').val(function(index,oldValue){
return "oldValue="+oldValue+"newValue=testNewValue"+"index="+index;
})
</script>