这个是为什么
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<style>
/*input:focus,textarea:focus{
border:1px solid #f00;
background:#fcc;
}*/
.focus{
border:1px solid #f09;
background:#fd3;
}
</style>
<body>
<form action="#" method="POST" id="regForm">
<fieldset>
<legend>个人基本信息</legend>
<div>
<label for="username">名称:</label>
<input type="text" id="username" />
</div>
<div>
<label for="pass">密码:</label>
<input type="password" id="pass" />
</div>
<div>
<label for="msg">详细信息:</label>
<textarea id="msg"></textarea>
</div>
</fieldset>
</form>
<script src="script/jq.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$(":input").focus(function(){
$(this).addClass("focus");
}).blur(function(){
$(this).removeClass("focus");
})
})
</script>
</body>
</html>
我标签和样式里面都没有涉及到伪类,我在用jQ时$(":input"),为什么3个框都有颜色变化?
正在回答
:input 选择器选取表单元素。选择所有 <input> 元素为:$(":input")
这个选择器就是这样使用的哦,所以会选中所有的input元素
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36713 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星