2

我最近拿了一份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>
        &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;
    });
})

但是单击“编辑”会出现错误:

fn 必须是一个函数

这有什么问题?

4

1 回答 1

2

在我看来,您对 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;
  });
})
于 2016-01-20T14:28:13.857 回答