我的前面是个label,图片是label的背景图,当我不点击文本框时,背景图片是灰色的这张,当我点击文本后背景图变成另外一张图片是否可以实现。谢谢
$("input").blur(function(){ //选择这个input
$("").attr("background-image","") //选择这个label
})
ipt是输入框的id,lb是label的id:
$('#ipt').focus(function(){//获取光标
$('#lb').css('background','另一种图片路径');
});
$('#ipt').blur(function(){//失去光标
$('#lb').css('background','原始图片路径');
});
css3来搞
<style>
div.input{border:solid 1px #999;}
div.input span{display:inline-block;background:url(50音图.jpg);width:30px;height:30px;float:left;}
div.input input:focus{border:solid 1px #666}
div.input input:focus ~ span{background:url(router-switch.jpg)}
</style>
<div class="input">
<input type="text" />
<span></span>
</div>
建议还是用js或jquery代码来实现,CSS3是可以实现,但是要处理浏览器支持度和兼容的问题,又是一个麻烦事。