将Jquery变量的值传递给window.open

时间:2013-05-31 14:04:15

标签: 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, 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>

2 个答案:

答案 0 :(得分:1)

据我所知:

$(".attachmentsUpload input.file").replaceWith('<input type="file" class="file" name="file" />');

那么:

$(".attachmentsUpload input.file").val()返回字符串为空

答案 1 :(得分:1)

您似乎在window.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");