twitter-bootstrap - Alertify 提示不起作用

标签 twitter-bootstrap alertify

我最近获取了 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 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/

相关文章:

javascript - Alertify 自动确认并提交表单,无需单击“确定”

twitter-bootstrap - 当在移动设备上查看我的 Twitter Bootstrap 网站时,两侧会添加 20 像素的装订线。我该如何阻止这个?

javascript - 使用 Bootstrap 在弹出窗口中出现问题

html - 标题隐藏在下拉菜单后面

jquery - Alertify 在确认之前执行?

html - body 100% 高度在某些 Action 上移动

javascript - 将复选框选择的值从一个 div 复制到另一个 div

html - Bootstrap 可滚动列,高度为 100%

javascript - 如何在 React 中使用 ALERTIFY JS?

javascript - 在 AlertifyJS 中使用 If 语句