作者:的士发个火 | 来源:互联网 | 2023-01-29 17:54
所以我试图强制保持引导模式显示甚至在切换按钮上单击使用$('#myModal').modal('show');
show方法在外部.click()函数时工作,但是当它在.click()函数内时没有说这样的方法
因此
$('document').ready(function() {
$('#my-toggle-button').click(function() {
$('#myModal').modal('show'); // Throws up the below error
});
});
错误:
Uncaught Error: Method show does not exist on jQuery.modal
at Function.error (jquery-2.2.4.min.js:2)
at n.fn.init.a.fn.modal (materialize.min.js:8)
at HTMLAnchorElement. (myScript.js:4)
at HTMLAnchorElement.dispatch (jquery-2.2.4.min.js:3)
at HTMLAnchorElement.r.handle (jquery-2.2.4.min.js:3)
但是它工作正常
$('document').ready(function() {
$('#myModal').modal('show'); // Works fine
$('#my-toggle-button').click(function() {
});
});
更新:
原因是由于脚本导入具有延迟和aysnc而导致它.我不知道什么是正确的地方使用这些因为他们不认识莫代尔.
1> 小智..:
当您还在使用materializecss时尝试执行引导模式时会出现此问题,最好的建议是使用materializecss模式.
http://materializecss.com/modals.html
//initialize all modals
$('.modal').modal({
dismissible: true
});
//call the specific div (modal)
$('#modal2').modal('open');
请享用!