我试图在选择文件上传时设置文本框的值,但它并没有发生,但我在警告框中看到了正确的值。
<div class="row">
<div class="col-xs-2">
<div class="file-label"><i></i>@Resources.FolderPath</div>
</div>
<div class="col-xs-4">
<input class=".form-control" name="fileText" type="text" />
<div class="fileUpload btn btn-primary">
<span>Browse</span>
<input type="file" name="File" id="fileUpload" class="upload"/>
</div>
</div>
<div class="col-xs-4">
<label id="fileSizeError" style="color: red"></label>
</div>
</div>
$(document).ready(function () {
$(document)
.on("change","#fileUpload",
function (e) {
alert($("#fileUpload").val());
$("#fileText").val($("#fileUpload").val());
alert("hi");
});
});
请在这里帮助我。我正在使用 Asp.net MVC 作为平台。
最佳答案
您的input
有一个name
,但是#fileText
是一个ID 选择器。向其添加 id
,或使用属性选择器来查找它。
所以要么:
<input class=".form-control" id="fileText" name="fileText" type="text" />
<!-- add id------------------^^^^^^^^^^^^^ -->
或
$("[name=fileText]").val($("#fileUpload").val());
// ^^^^^^^^^^^^^^^---- use attribute selector
关于javascript - Jquery 不设置文本框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38485959/