jquery表单对象属性选择器

时间:2024-05-21 09:34:32
<!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>
<title>表单对象属性选择器</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
.yang{ border-collapse: collapse; width:500px;height:30px;border:1px solid red;"}
</style>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
/*
:enabled //匹配状态可用的表单元素
:disabled //匹配状态不可用的表单元素
:checked //匹配被选中的元素
:selected //匹配被选中的元素(单指下拉列表 option)
*/
window.onload=function(){
$('#btnOk').click(function(){
//隐藏所有的可用元素并隐藏
//$(':enabled').hide(); //隐藏所有的不可用元素并隐藏
//$(':disabled').hide(); //匹配被选中的元素
//$(':checked').hide(); //匹配被选中的元素(单指下拉列表 option)
//$(':selected').hide();
       alert($(':selected').val());
});
};
</script>
</head>
<body>
<input type='text' disabled="disabled"/>
<hr/>
<input type='password' />
<hr/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type="checkbox"/>
<input type='file' />
<hr/>
<select></select>
<hr/>
<textarea></textarea>
<select>
<option>北京</option>
<option>山东</option>
<option>河北</option>
</select>
<input type="button" id='btnOk' value='确定' />
</body>
</html>