我最近获取了 Alertify
库的副本,但无法prompt
工作。
我的应用程序是使用 Bootstrap 的 .NET MVC。
这是我的 html 的一个片段(删除了大部分选项标签以提高可见性):
<div class="row">
<div class="col-md-3">
Model
</div>
<div class="col-md-9">
<select id='selmodels' class='w250' type='model'><option class='w250' value='0'></option></select>
<div id="edit" class="btn btn-default">Edit</div>
</div>
</div>
这是脚本(这是不同的,但在调试时更改为alertify示例):
$(document).ready(function () {
$('#edit').click(function () {
//var name = $('#selmodels option:selected').text();
alertify.prompt('This is a prompt dialog!', 'some value',
function(evt, value) { alertify.message('You entered: ' + value); }
);
return false;
});
})
但是单击“编辑”会出现错误:
fn must be a function
这有什么问题吗?
最佳答案
在我看来,您对alertify提示方法的参数使用了错误的顺序。正确的模板如下:
alertify.prompt('Insert your message here:', function (e, str) {
if (e) {
// e corresponds to an "OK" press.
// str is the value of the prompt textbox.
} else {
// else corresponds to a "Cancel" press.
}
}, 'Insert the default textbox message here.');
因此只需更改提示方法中参数的顺序即可。您的代码最终应该如下所示:
$(document).ready(function () {
$('#edit').click(function () {
//var name = $('#selmodels option:selected').text();
alertify.prompt('This is a prompt dialog!',
function(evt, value) { alertify.message('You entered: ' + value); }
'some value'
);
return false;
});
})
关于twitter-bootstrap - Alertify 提示不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34899980/