我的代码中的什么内容给了我这个错误?
jquery-2.1.3.min.js:3 Uncaught RangeError: Maximum call stack size exceeded
HTML
<form id="addPhotoForm">
<img class="pull-right" src="" width="100px" height="140px"/>
<input type="file" id="addPhotoInput" name="addPhotoInput" style="display: none;"/>
</form>
JS
//On click Photo
$('#addPhotoForm').on('click', function(){
//Check if usrname exist
var usrname = $('#usrname').val();
if(usrname){
$('#addPhotoInput').trigger('click');
}
else{
alert("!");
}
})
如何解决这个错误?
我试图在单击表单时打开文件对话框。
更新
我尝试过:
$('#addPhotoInput').click();
最佳答案
为了避免使用 jQuery 绑定(bind)的任何单击事件处理程序被触发,并仍然保持事件传播(如果也绑定(bind)了任何委托(delegate)单击事件,则很有用),您可以调用 native DOM click()
方法:
$('#addPhotoInput')[0].click();
或者:
$('#addPhotoInput').get(0).click();
与以下内容相同:
document.getElementById('addPhotoInput').click();
关于javascript - Jquery .click() 给我 "stack size exceeded",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38095542/