我想用一个小的jQuery来“隐藏”Google搜索框中的初始值,当你在框中单击时,我错过了一些东西。如何从Google搜索框中删除默认的Google搜索值?
下面是搜索框代码:
<div id="search_box">
<form action="http://mfrp.ehclients.com/search_results" id="cse-search-box">
<div>
<input type="hidden" name="cx" value="017425724926122041548:1ccj3d-e1-s" />
<input type="hidden" name="cof" value="FORID:9" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="text" id="q" name="q" value="Search..." size="31" />
</div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
</div>
这里是jQuery的:
<script type="text/javascript">
$('#q').click(function() {
if($(this).val() == 'Search...')
$(this).val('');
});
</script>
唯一的问题是,这是行不通的。这里是page。
我希望有一些帮助整理出来。
感谢,
阿甘
尝试console.log($(this).val())并查看它给了你什么。 – hookedonwinter 2010-07-23 22:56:47
当我把你的javascript代码粘贴到firebug中并运行它时,它会做它应该做的事情。 (文档).ready(函数(){/ *代码* /} – Davis 2010-07-23 22:57:46
嗨Luvat,你是正确的!我添加了(文档).ready并且它工作。 – fmz 2010-07-23 23:46:19