开发者

js input onBlur not worked when the page onload

开发者 https://www.devze.com 2023-03-11 03:51 出处:网络
The link example is here: http://jsfiddle.net/fxr5p/ How to make if value is empty, onload work onblur function? show type your keyword, then click the input part, onblur word disapear? Thanks.

The link example is here: http://jsfiddle.net/fxr5p/ How to make if value is empty, onload work onblur function? show type your keyword, then click the input part, onblur word disapear? Thanks.

<input type="text" value=""  id="search" name="Search" onblur="if(this.value=='') this.value='type your keyword';" onfocus="if(this.value=='type your keyword') this.开发者_如何学编程value='';">


<script>
  document.body.onload = function ()
  {
    document.getElementById("search").value = "type your keyword";
  }
</script>


Try this:

<input type="text" value="type your keyword"  id="search" name="Search" onblur="if(this.value=='') this.value='type your keyword';" onfocus="if(this.value=='type your keyword') this.value='';">


I think you're almost there, just use value="type your keyword".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号