开发者

Search box in jQuery mobile go empty on focus, revert back to default text ONLY when it is empty AND loses focus?

This is what I am doing right now, but it does not clear the text when it gains focus, nor does it repopulate with the default text when it is empty and loses focus:

//html
<input type="search" style="color:#858585" id="numbersearch" value开发者_StackOverflow社区="Search..." />

//java script
$(document).ready(function() {
var value = $("#numbersearch").val();
$("#numbersearch").focus(function() {
    if(value == "Search...") {
    value="";
    }
});

$("#numbersearch").blur(function() {
    if(value == "") {
    value="Search...";
    }
});
});


HTML5 placeholder

<input type="text" placeholder="this is some text" id="test" />

jQuery if you still want (Link):

$('input[type=text]').focus(function() { 
    if($(this).val() == $(this).attr('defaultValue')) {
        $(this).val('');
    }
});

$('input[type=text]').blur(function() {
    if($(this).val() == '') {
        $(this).val($(this).attr('defaultValue'));
    } 
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜