gpt4 book ai didi

javascript - 尝试使用 jquery 表单提交,但不起作用

转载 作者:行者123 更新时间:2023-12-02 19:05:24 24 4
gpt4 key购买 nike

我正在尝试使用 jquery 将表单数据发布到新窗口。但我失败了。

我的源码是这样的

<!doctype html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.min.js" > </script>
<script type="text/javascript">
function submit_with_jquery(){
var $form = $("<form></form>");
var $input = $("<input name='imgInput' />");
$form.prop("target", "photo_top")
.prop("method", "post")
.prop("action", "/common/board/photoViewWindow.jsp")
.append($input)
.bind("submit",
function(){
window.open('','photo_pop','width=720,height=530,toolbar=no,resizable=no,scrollbars=no,left=50,top=50');
} )
.submit();
}
</script>
</head>
<body>
<input type="button" onclick="submit_with_jquery()" value="submit with jquery" />
</body>
</html>

(*我编辑并将 attr 更改为 prop,但是)它仅显示 about:blank...

然后,我尝试了这段代码并成功了。

<!doctype html>
<html>
<head>
<script type="text/javascript">
function submit_with_tag(){
window.open('','photo_pop','width=720,height=530,toolbar=no,resizable=no,scrollbars=no,left=50,top=50');
} </script>
</head>
<body>
<form id="tagForm" action="/common/board/photoViewWindow.jsp" target="photo_pop" onSubmit="submit_with_tag()">
<input name="imgInput" type="hidden"/>
<input type="submit" value="submit with tag"/>
</form>
</body>
</html>

我认为它的工作原理是相同的,但 jQuery 代码却不是。 为什么我的第一个代码不起作用?我哪里做错了?

最佳答案

您的目标“photo_top”,您打开的窗口名为'photo_pop'

除此之外,Ajax 可能是比第一种方法更好的选择,在第一种方法中,您手动构建表单元素只是为了提交它们。

关于javascript - 尝试使用 jquery 表单提交,但不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14349569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com