:text Selector
text selector
version added: 1.0jQuery(':text')
描述: 選擇所有類型為文本的元素。
$(':text')等價(jià)于$('[type=text]')。如同其他偽類選擇器(那些以“:”開始)建議前面加上一個(gè)標(biāo)記名稱或其他選擇器;否則,通用選擇("*")被默認(rèn)使用。換句話說(shuō)$(':text') 等同于 $('*:text'),所以應(yīng)該使用$('input:text')。
Example:
Finds all text inputs.
<!DOCTYPE html>
<html>
<head>
<style>
textarea { height:25px; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<form>
<input type="button" value="Input Button"/>
<input type="checkbox" />
<input type="file" />
<input type="hidden" />
<input type="image" />
<input type="password" />
<input type="radio" />
<input type="reset" />
<input type="submit" />
<input type="text" />
<select><option>Option</option></select>
<textarea></textarea>
<button>Button</button>
</form>
<div>
</div>
<script>
var input = $("form input:text").css({background:"yellow", border:"3px red solid"});
$("div").text("For this type jQuery found " + input.length + ".")
.css("color", "red");
$("form").submit(function () { return false; }); // so it won't submit
</script>
</body>
</html>