我在html页面上有一堆<a>
个,每个都与一个form
相关联,并希望显示一个“加载”图像,而表单本身就是总和(这似乎需要很长时间,但是也许这是另一回事。)
所以我在那些a
s的onclick事件中做了一些有点hackish的事情
frmContent = $ ( this ).nextAll ( "form" ).clone ();
$ ( "body" ).html ( "<div class='preload'><img src='./img/loading.gif' /><br/>Caricamento in corso<\/div>" );
$ ( "body" ).append(frmContent);
frmContent.submit ();
这似乎适用于Firefox和IE9。问题是当启用兼容模式时,这不起作用。
当浏览器被识别为IE7时,我也想过使用不同的东西,如下所示:
if ( $.browser.version != "7.0" ) {
frmContent = $ ( this ).nextAll ( "form" ).clone ();
$ ( "body" ).html ( "<div class='preload'><img src='./img/loading.gif' /><br/>Caricamento in corso<\/div>" );
$ ( "body" ).append(frmContent);
frmContent.submit ();
} else {
$ ( this ).nextAll ( "form" ).submit ();
}
因此未显示预加载动画,但这违背了目的。
由于我无法强制我的用户关闭兼容模式,并且由于此页面也必须在IE7中运行,因此该代码段有什么问题?有没有更好的方法来做到这一点。
答案 0 :(得分:2)
在提交之前将表单附加到正文。
frmContent = $ ( this ).nextAll ( "form" ).clone ();
$ ( "body" ).html ( "<div class='preload'><img src='./img/loading.gif' /><br/>Caricamento in corso<\/div>" );
frmContent.hide();
$ ( "body" ).append(frmContent);
frmContent.submit ();
像解决方法一样。我认为没有理由用preload div替换所有正文HTML并克隆表单。您可以在提交之前隐藏所有内容并附加preload div:
$ ( "body" ).children().hide();
$ ( "body" ).append( $("<div class='preload'><img src='./img/loading.gif' /><br/>Caricamento in corso<\/div>") );
$ ( this ).nextAll ("form").submit();