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'));
}
});