2

この変数の HTML フィールドの値を警告する次の Jquery コードがあります。$(".attachmentsUpload input.file").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");

しかし、値を渡していません。

<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>
4

2 に答える 2

1

私が理解しているように:

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

それで:

$(".attachmentsUpload input.file").val()空の文字列を返します

于 2013-05-31T14:10:51.610 に答える