开发者

Clicking placeholder doesn't make input active

I am using a work-around for HTML5 placeholder using jQuery. The only problem is that if I click on the placeholder <span> itself, the input field doesn't become active. For it to become active I have to click inside the input but outside of the placeholder.

Here is a jsFiddle showing what's go开发者_如何学运维ing on: http://jsfiddle.net/QXeQy/1/

If I give the span a negative z-index it disappears. How can I fix this?


Your span is in the way of your input. Try adding this:

$("span.holder").click(function() {
    $(this).next().focus();
});

http://jsfiddle.net/QXeQy/2/


instead of span use <label>

<label for="search">Placeholder text</label><input type="search" name="search" id="search" />

and then use this javascript:

$('#search').focus(function(){
  $('label[for=search]').hide();
}

$('#search').blur(function(){
  if($('#search').val() == '' )
    {
      $('label[for=search]').show();
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜