Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
选中时在文本框中使用javascript隐藏图像_Javascript_Jquery_Html_Css - Fatal编程技术网

选中时在文本框中使用javascript隐藏图像

选中时在文本框中使用javascript隐藏图像,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想更改文本框内图像的可见性。 当我选择文本框“搜索”时,占位符将不可见。 你可以用里面的图片做同样的事情吗 守则: <div id="ricerca"> <form > <input type="text" class="ricerca" value="Search" onblur="if (this.value == '') this.value ='Search';" onclick="i

我想更改文本框内图像的可见性。 当我选择文本框“搜索”时,占位符将不可见。 你可以用里面的图片做同样的事情吗

守则:

<div id="ricerca">
                  <form >
                  <input type="text" class="ricerca" value="Search" onblur="if (this.value == '') this.value ='Search';" onclick="if (this.value == 'Search') this.value ='';"  >
                  <input type="submit"  id="lente" class="lente"  value="show" style="border:none;">
                  </form> 
</div>  


这是链接:

这对你有用吗>

<style type="text/css">
input.image-placeholder{
    background-image:url("image path");
    background-repeat:no-repeat;
    background-position: center left;
}
</style>

<div id="ricerca">
              <form >
              <input type="text" class="ricerca" value="Search" onblur="if (this.value == '') this.className= this.className + ' image-placeholder';" onclick="if (this.value == 'Search') this.className='ricerca';"  >
              <input type="submit"  id="lente" class="lente"  value="show" style="border:none;">
              </form> 
</div>

input.image-placeholder{
背景图像:url(“图像路径”);
背景重复:无重复;
背景位置:左中;
}

为您提供一些Jquery功能

$(".ricerca").click(function() {
  $("#lente").hide();
 });
$(".ricerca").focusout(function() {
  $("#lente").show();
  $("#lente").css('marginTop',"-22px");
 });

看看这里

是的,你可以。。你尝试过什么?我对javascript不是很熟悉,但我尝试过一些IF,并给图像提供一个ID。是的,有很多方法可以做到…例如,以前我使用css block none…但我认为jquery hide show会非常简单。。