MWh*_*ore 2 javascript forms iframe jquery
我可能过于复杂,但对整个过程来说相对较新,我不知道还能做什么.我在iframe中有一个订单表单,它位于jQuery UI对话框灯箱内.这一切都有效,除了一个问题:当提交表单并将其重定向到感谢或错误页面时,它会在底部滚动.
我尝试过使用onload="window.parent.scroll(0,0);"感谢和错误页面的标签,但是没有做任何事情.
还尝试过:
<script type="text/javascript">
$("#orderform").onsubmit(function() {
$("#dialog").window.scrollTo(0,0);
alert('triggered');
});
</script>
Run Code Online (Sandbox Code Playgroud)
我已将脚本放在我能想到的任何地方,索引页面,对话框内部,iframe内部,窗体页面中,甚至都没有得到警报.
目前托管该网站的测试服务器是http://kinnill.com/dev/bluehydrangea/
不确定要滚动到顶部的页面.对话框,对话框所在的页面或iframe中的页面?
看完你的代码后,我相信这就是你所追求的:
如果对话框有一个可在iframe更改后向下滚动的可滚动元素,那么您将需要定位具有"overflow:auto"的任何元素.如果该元素是#dialog,那么在表单所在的iframe页面上执行此操作(在您的情况下看起来是form.php):
<script type="text/javascript">
$(function(){
$("#orderform").submit(function() {//note: in jquery the onsubmit event is called "submit"
$('#dialog', window.parent.document).scrollTop(0);//target #dialog from the parent window
alert('triggered');
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
其他可能的解决方案供其他人参考:
如果对话框所在的页面,请执行以下操作:
如果表单位于iframe中,则代码需要位于iframe中.然后,您需要修改代码以定位父窗口.
这应该是你正在寻找的:
<script type="text/javascript">
$("#orderform").submit(function() {
$(window.parent).scrollTop(0);
alert('triggered');
});
</script>
Run Code Online (Sandbox Code Playgroud)
如果你要滚动的页面是感谢页面或错误页,然后把下面的感谢信和错误页面:(您需要的感谢信和错误页面的jQuery)
<script type="text/javascript">
$(function(){
$(window).scrollTop(0);
});
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4790 次 |
| 最近记录: |