Alertify 提示不起作用

Alertify prompt not working

我最近获取了 Alertify 库的副本,但无法使 prompt 工作。

我的应用程序是 .NET MVC,使用 Bootstrap。

这是我的 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>
        &nbsp;
        <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;
    });
})

但是单击 'Edit' 会出现错误:

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;
  });
})