我正在尝试从onchange事件的另一个按钮触发按钮单击事件。但事件发生后我得到以下错误,没有按钮事件不起作用,下面是我的代码,任何人都可以帮助我。
<script type="text/javascript">
document.getElementById('btnPropertyUpload').addEventListener('click', openDialog);
function openDialog() {
console.log("funOnchange");
document.getElementById('imgPropertyUpload').click();
}
function funOnchange() {
$('#btnPropertySubmit').click();
}
</script>
<div align="left">
@using (Html.BeginForm("PropertyMaster", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" })) {
<span style="padding:5px 0px 0px 30px;">
@Html.Label("lblPropPhotos", "PROPERTY PHOTOS")
</span>
<button type="button" id="btnPropertyUpload" class="btn-link">
<span class="glyphicon glyphicon-upload col-sm-2"></span>
</button>
<input type="file" id="imgPropertyUpload" style="display:none" name="postedFiles" multiple="multiple" onchange="funOnchange();" />
<input type="submit" value="Upload" id="btnPropertySubmit" style="display:none" />
<br />
if (Model != null && Model.PropDetails.PropertyImages != null)
{
foreach (var image in Model.PropDetails.PropertyImages) {
<img src="@Url.Content(image)" style="width:100px;height:100px; padding:5px 0px 0px 30px;" />
}
}
}
</div>
答案 0 :(得分:0)
试试这个 - imgPropertyUpload是文件输入,所以不要点击try focus,你可以使用jquery进行所有编码
$(document).ready(function(){
$('#btnPropertyUpload').on('click', function(){openDialog()});
});
function openDialog() {
console.log("funOnchange");
$('#imgPropertyUpload').focus();
}
function funOnchange() {
$('#btnPropertySubmit').click();
}