[jQuery] Form中会导致IE6崩溃的提交 -- Crash of the form in IE6

本文介绍了一个在Internet Explorer 6中遇到的表单提交问题,当用户在搜索框内输入文本并按下回车键时,浏览器会意外关闭。文章提供了具体的HTML和JavaScript代码示例,并给出了修改后的解决方案。

页面代码如下: -- As the code below

ContractedBlock.gifExpandedBlockStart.gif代码
<form onsubmit="sbSearch();return false;" method="get" action="test.php" id="sbSearchForm">
  <label style="display: none;" for="sbText">sbText</label>
  <input type="text" onclick="if(this.value=='Search text')this.value=''" onblur="if(this.value=='')this.value='Search text';" value="Search text" name="SearchText" id="sbText" />
  <input type="submit" value="submit" />
</form>
<script type="text/javascript">
//<![CDATA[
function sbSearch()
{
if(jQuery("#sbText").val() == "Search text" || jQuery("#sbText").val() == "")
{
alert(
"Please fill the field");
jQuery(
"#sbText").focus();
return false;
    }
    else
    {
    jQuery(
"#sbSearchForm").submit();
    }
}
//]]>
</script>

 

在 IE6下,当输入文字,然后回车,会出现浏览器关掉的问题。

Under IE6, aftering inserted the words, and then press the enter, then the browser will close selftly.


现在找到的解决办法, 如下面javascript里面红色加粗。

Now the resolved as below, pay attention to the code in javascript marked red bold.

ContractedBlock.gifExpandedBlockStart.gif代码
<script type="text/javascript">
//<![CDATA[ 
function sbSearch()
{
if(jQuery("#sbText").val() == "Search text" || jQuery("#sbText").val() == "")
{
alert(
"Please fill the field!");
jQuery(
"#sbText").focus();
return false;
}
else
{
jQuery(
"#sbSearchForm")[0].submit();
}
}
//]]>
</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值