<form action="" method="post" id="regForm">
<label for="username">名称:</label>
<input id="username" type="text" value="名称" />
</form>
.focus {
border: 1px solid #f00;
background:#CCC;
}
<script src="jquery-1.9.1.js" type="text/javascript">
$(function(){
$(":input").focus(function(){
$(this).addClass("focus");
if($(this).val() ==this.defaultValue){
$(this).val("");
}
}).blur(function(){
$(this).removeClass("focus");
if ($(this).val() == '') {
$(this).val(this.defaultValue);
}
});
})
</script>
当input字段获得焦点时,背景和边框都应该会有变化?为什么我的没有?
求大神们指点
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
应该是两个script标签吧
script标签,src引用和代码实体部分应该分开写,有src引用的部分内容一定要留空。