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 の prompt メソッドの引数の順序が間違っているようです。正しいテンプレートは次のとおりです。

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 に答える