将值从Jquery变量传递到window.open
我有以下Jquery代码,用于警告此变量将值从Jquery变量传递到window.open,jquery,Jquery,我有以下Jquery代码,用于警告此变量$(“.attachmentsUpload input.file”).val()中HTML字段的值 我的问题是我想像这样把这个值传递给变量val window.open("http://abc.com/crop/test.php?val="+$(".attachmentsUpload input.file").val()),"_blank","toolbar=yes, location=yes, directories=no, status=no, men
$(“.attachmentsUpload input.file”).val()中HTML字段的值代码>
我的问题是我想像这样把这个值传递给变量val
window.open("http://abc.com/crop/test.php?val="+$(".attachmentsUpload input.file").val()),"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
但它并没有传递价值
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript'>//<![CDATA[
$(function(){
$(".attachmentsUpload input.file").live("change", function () {
if ($(".attachmentsUpload input.file").val() == "") {
return;
}
// your ajax submit
alert("submit value of the file input field=" + $(".attachmentsUpload input.file").val());
$(".attachmentsUpload input.file").replaceWith('<input type="file" class="file" name="file" />');
});
});//]]>
window.open("http://abc.com/crop/test.php?val="+$(".attachmentsUpload input.file").val()),"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
</script>
</head>
<body>
<form class="attachmentsUpload" action="/UploadHandler.ashx" method="post" enctype="multipart/form-data">
<input type="file" class="file" name="file" />
</form>
</body>
</html>
//
窗口打开(“http://abc.com/crop/test.php?val=“+$(“.attachmentsUpload input.file”).val(),“\u blank”,“工具栏=是,位置=是,目录=否,状态=否,菜单栏=是,滚动条=是,可调整大小=否,复制历史=是,宽度=400,高度=400”);
据我所知:
$(".attachmentsUpload input.file").replaceWith('<input type="file" class="file" name="file" />');
$(“.attachmentsUpload input.file”).replacetwith(“”);
那么:
$(“.attachmentsUpload input.file”).val()
返回空字符串看起来您在窗口中有一个额外的近亲。open
语句。
尝试将val())
更改为val()
所以:
window.open("http://abc.com/crop/test.php?val="+$(".attachmentsUpload input.file").val()+","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
请显示您的html,尤其是此输入。注意:不要使用live(),而是使用on()。看起来在窗口中有一个额外的近亲。open
语句。尝试将val())
更改为val()
?@ckpepper02 HTMLadded@ckpepper02很好,很有效:)如果这解决了你的问题,我的评论就是一个答案。