Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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
Search jQuery mobile中的搜索框在焦点处变空,只有当它为空并失去焦点时才恢复为默认文本?_Search_Text_Focus_Jquery Mobile_Blur - Fatal编程技术网

Search jQuery mobile中的搜索框在焦点处变空,只有当它为空并失去焦点时才恢复为默认文本?

Search jQuery mobile中的搜索框在焦点处变空,只有当它为空并失去焦点时才恢复为默认文本?,search,text,focus,jquery-mobile,blur,Search,Text,Focus,Jquery Mobile,Blur,这就是我现在正在做的,但当文本获得焦点时,它不会清除文本,当文本为空且失去焦点时,它也不会重新填充默认文本: //html <input type="search" style="color:#858585" id="numbersearch" value="Search..." /> //java script $(document).ready(function() { var value = $("#numbersearch").val(); $("#numbersearch

这就是我现在正在做的,但当文本获得焦点时,它不会清除文本,当文本为空且失去焦点时,它也不会重新填充默认文本:

//html
<input type="search" style="color:#858585" id="numbersearch" value="Search..." />

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

$("#numbersearch").blur(function() {
    if(value == "") {
    value="Search...";
    }
});
});
//html
//java脚本
$(文档).ready(函数(){
var值=$(“#numbersearch”).val();
$(“#numbersearch”).focus(函数(){
如果(值==“搜索…”){
value=“”;
}
});
$(“#numbersearch”).blur(函数(){
如果(值==“”){
value=“搜索…”;
}
});
});


谢谢,效果很好。我想我尝试的一切都是旧东西=[
<input type="text" placeholder="this is some text" id="test" />
$('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'));
    } 
});