<a href= "javascript:void(0)" onclick= "test();" >ceshi</a>
|
01 |
var comment = document.getElementsByTagName( 'a' )[0];
|
02 |
comment.href = "2.html" ;
|
03 |
//alert(comment.href);
|
04 |
if (document.all) {
|
05 |
// For IE
|
06 |
comment.click();
|
07 |
} else if (document.createEvent) {
|
08 |
//FOR DOM2
|
09 |
var ev = document.createEvent( 'HTMLEvents' );
|
10 |
ev.initEvent( 'click' , false , true );
|
11 |
comment.dispatchEvent(ev);
|
12 |
comment.click();
|
IE验证没问题。火狐进入死循环。。。
最终解决办法:
01 |
var comment = document.getElementsByTagName( 'a' )[0];
|
02 |
comment.href = "2.html" ;
|
03 |
//alert(comment.href);
|
04 |
if (document.all) {
|
05 |
// For IE
|
06 |
comment.click();
|
07 |
} else if (document.createEvent) {
|
08 |
//FOR DOM2
|
09 |
var ev = document.createEvent( 'HTMLEvents' );
|
10 |
//ev.initEvent('', false, true);
|
11 |
comment.dispatchEvent(ev);
|
12 |
comment.click();
|