2016-01-20 64 views
1

我最近抓到Alertify庫的副本,但無法獲得prompt的工作。Alertify提示不起作用

我的應用程序是使用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

什麼是錯的w ^這是什麼?

回答

1

在我看來,您對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; 
    }); 
}) 
+0

你說得對。 http://alertifyjs.com/prompt.html上的示例是錯誤的!謝謝 :) – CompanyDroneFromSector7G