IE6下的问题真多,这两天连续遇到好几个,包括IE6下tr不能加border边框样式,其他都ok。今天又遇到form表单里面用a链接模拟表单提交事件,发现在js里面执行表单的submit事件,后台也正常接收到事件,而IE6下用httpwatch调试后发现该处理请求 aborted before response message was received。其他浏览器包括chrome,ff,IE7以上,360也是得高版本都没问题。
原来在form表单里面的a链接写法为
<form id='applyForm'> <div class="submit-back"> <a class="sub-button" href="javaScript:void(0);" ></a> </div> </form>
js
$('.submit-back').click(function(){
//...表单验证
$('#applyForm').submit();
});
然后点击a链接,则出现上面那种case。
网上找了一些资料之后,IE6下的问题
The (Aborted) value is more complex in its origin. It occurs when IE has started to process the request for a URL (e.g. to download an image), but then decides to cancel the operation. Here are some examples of when this can occur:
If you click on a link or bookmark while a page is downloading, or click on IE’s Stop button, you will see that IE cancels any requests which are still active and HttpWatch shows the (Aborted) result.
A CSS rollover image on a page will start a request when the mouse pointer is moved into its active area. If the mouse pointer quickly moves away again, IE may abort the request if it has not already completed.
Sometimes javascript is used to fire off requests for background tasks or to gather statistics on a page. Often this can lead to aborted results if the javascript does not wait for the response to be received from the server.
继续寻找根源,搜索到发现这个问题是ie6中一个底层 机制的bug,之后的版本已经解决了。据说<a href="javascript:void(0)">或者<a href=#">这样使用a标签的话并不能阻止a标签最后触发一个什么行为,导致ie6会错误的认为页面刷新或者重定向了,并且中断了当前所有连 接,这样新的加载就被aborted了。解决方案最简单的方法有两个,一个是这样使用a标签<a href="xxx(); return false;">,另外一个就是用div替换a标签来用。至此,问题总算解决。
解决方案
1 不使用onclick,但必须保证处理函数不返回值,否则浏览器将清空页面,只显示函数的结果。如果
test 返回false,浏览器中就会显示false。
<
a
class=
"sub-button"
href=
"javaScript:test();"
></
a
>
2.在onclick上加return false阻止浏览器执行href。href属性还是必须的,否则链接就样式失效了
<div class="submit-back"> <a class="sub-button" href="javaScript:void(0);" οnclick="return false;"></a> </div>