表单选择器展示

Original 2019-06-01 16:26:08 205
abstract:<!DOCTYPE html><html><head><meta charset="utf-8"> <title>jQuery选择器</title> <script type="text/javascript"src="jquery-3.3.1.min.js"&

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>jQuery选择器</title>

<script type="text/javascript"src="jquery-3.3.1.min.js"></script>

<style type="text/css">

 div{width: 100px;height: 100px; background: #ccc;margin-top: 20px;}


</style>

</head>

<body>

 

<script type="text/javascript">


//

表单选择器

 $(document).ready(function(){

   $(':enabled').css('background','pink')

   $(':disabled').css('background','red')

   $(':selected').css('color','blue')

   $(':checked').parent().css('color','red')

 })

</script>

<form>

 输入框1<input type="text" name=""><br>

 输入框2<input type="text" name=""><br>

 输入框3<input type="text" name="" disabled><br>

 输入框4<input type="text" name=""><br>

 <select>

   <option>摩羯座</option>

   <option selected>双鱼座</option>

   <option>射手座</option>

   <option>天蝎座</option>

 </select>

 <br>

 爱好:

 <label><input type="checkbox" name="">看书</label>

 <label><input type="checkbox" name="" checked>游泳</label>

 <label><input type="checkbox" name="">游戏</label>

</form>

</body>

</html> 


Correcting teacher:天蓬老师Correction time:2019-06-03 09:55:52
Teacher's summary:考虑到与CSS3的兼容性, 推荐在表单中, 使用属性选择器, 替换掉jQuery自创的 例如: $(':input'), 应该用: $('input[type="text"]')之类的替代

Release Notes

Popular Entries