jquery val方法
舉個(gè)例子
<html>
<head>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert($("input").val());
alert($("input").eq(1).val());
});
});
</script>
</head>
<body>
Firstname: <input type="text" name="fname" value="Bill" /><br />
Lastname: <input type="text" name="lname" value="Gates" /><br /><br />
<button>獲得第一個(gè)文本域的值</button>
</body>
</html>
其中
alert($("input").val());
也可以寫成
alert($("input:text").val());
val方法是干嘛的?
獲取input標(biāo)簽的value屬性的泻仙。
有參數(shù)嗎糕再?
沒(méi)有的話就是獲取屬性值,有的話就是修改屬性值玉转。
還有其他函數(shù)可以做到這個(gè)么突想?
還沒(méi)發(fā)現(xiàn)其他的。
參數(shù)可以是函數(shù)嗎究抓?
可以猾担,只有函數(shù)有返回值,也就是(return)刺下,那么return的內(nèi)容就會(huì)成為绑嘹。input輸入框里的內(nèi)容。