有两种方法:
Html代码如下:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 5 <title>无标题文档</title> 6 </head> 7 8 <body> 9 <div> 10 <span id="search-keywords"> 11 <input type="text" name="keyword" id="keyword" size="40" onclick="if(value==defaultValue){value='';this.style.color='#333'}" onBlur= "if(!value){value=defaultValue;this.style.color='#ccc'}" value="输入产品,公司名称查找公司," style="font-family:微软雅黑;"/> 12 </span> 13 <span id="search-put"><input type="submit" value="搜索" /> 14 </span> 15 16 <form id="form1" name="form1" method="post" action=""> 17 18 <input name="textfield" type="text" size="36" id="textfield" value="Dreamweaver" onmouseover="this.style.borderColor='#FF6600'" onmouseout="this.style.borderColor=''" onFocus="if (value =='Dreamweaver'){value =''}" onBlur="if (value ==''){value='Dreamweaver'}"/> 19 <span id="search-put"><input type="submit" value="搜索" /> 20 </span> 21 </form> 22 </div> 23 </body> 24 </html>
JS代码如下:
<script language="javascript" type="text/javascript"> function newgetSearch(obj) { alert(obj) var kid = "keyword"; var fid = "frm"; var tid = "language_compsearch" if (StringTrim($("#" + kid).val()) == "" || $("#" + kid).val() == "输入产品,公司名称查找公司!") { myalert("请输入关键字"); return false; } else { var l = $("#" + tid).val(); var url = "/"; var str = StringTrim(obj.replace(/[^a-z0-9]+/gi,' ')); if(str == ""){ myalert("输入产品,公司名称查找公司!"); return false; } $("form[name='" + fid + "']").attr("action", url); return true; } } </script>