如何在文本框内放置背景图片 [英] How to put background image inside textbox
本文介绍了如何在文本框内放置背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前的代码不会工作:
p> < input onfocus =this.style.background ='images / activebutton.png'/>
解决方案
CSS是首选方法
CSS
<风格>
input [type =text]:focus {
background-image:url('images / activebutton.png');
}
< / style>
HTML
< input type =text/>
如果您仍想使用JavaScript,您需要这样做
< input type =text
onfocus =this.style.backgroundImage ='url (图像/ activebutton.png)';
onblur =this.style.backgroundImage =''
/>
does anyone know how to put background image inside a textbox? i want to do is when i click the textbox it will change the background with an image.Does anyone know how to do that?
my current code wont work:
<input onfocus="this.style.background='images/activebutton.png'" />
解决方案
CSS is the preferred method
CSS
<style>
input[type="text"]:focus{
background-image: url('images/activebutton.png');
}
</style>
HTML
<input type="text" />
If you still want to use JavaScript you need to do like this
<input type="text"
onfocus="this.style.backgroundImage='url(images/activebutton.png)';"
onblur="this.style.backgroundImage=''"
/>
这篇关于如何在文本框内放置背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文