2014-11-06 34 views
1

你會如此善待啓發我;我有以下問題Bootbox:如何添加'提示'

jcertify.html有:

<!-- Bootbox utilities 
    ================================================== --> 
    <script src"../static/assets/js/email_sign_up.js"></script> 
    </body> 

email_sign_up.js有:

function emailSignUp() 
{ 
    bootbox.prompt("<strong>Email address</strong>Enter email address where the report should be send to : ", function(result) {     
     if (result) { 
      // Example.show("email: <b>"+result+"</b>");  
      console.log("NikoS"); 
     } 
    }); 
} 

jcertify.html它像:

<p><a href="javascript:console.log('hi there');emailSignUp();" class="bb-trigger btn btn-primary btn-lg btn-block">Sign up</a></p> 

在瀏覽器的調試器,當我點擊「註冊」按鈕,我看到的是:

[登錄]您好(jcertify,1號線) [錯誤]的ReferenceError:找不到變量:emailSignUp global code(jcertify,line 1)

你知道我在做什麼錯嗎?

+0

你能檢查email_sign_up.js成功被加載到瀏覽器? – Shriike 2014-11-06 15:44:36

+0

未加載?爲什麼如此,因爲它被引用? – iamsterdam 2014-11-06 15:47:23

+0

那麼有很多原因。也許你的道路實際上是不正確的。也許在函數聲明前的文件開始處有一個javascript錯誤。確實很難調試。在瀏覽器的控制檯中,您可以嘗試輸入emailSignUp()並查看是否有效。 – Shriike 2014-11-06 16:26:18

回答

0
$(document).ready(function() { 

    $(document).on("click", "#signin_session", function(event) { 
     event.preventDefault() ; 

     bootbox.prompt("<strong>Email address</strong><br>Please enter the email address where the report should be send to : ", function(email_address) { 
       if (email_address) { 

        formulate   = {'email_address': email_address} ; 
        $.ajax({ 
         url:   "/jcertify/session-report/", 
         data:   JSON.stringify(formulate,null), // {'email_address': email_address}, 
         type:   "POST", 
         contentType: "application/json;charset=UTF-8", 
         success:  function(response) { document.write(response) ; }, 
         error:   function(error) { console.log(error) ; } 
        }); 

       } 
     }); 

    }); 
}); 
+0

:這是工作解決方案。 – iamsterdam 2014-11-25 09:34:00

0

入住此的jsfiddle:

http://jsfiddle.net/f75nfL26/1/

HTML:

<a class="bb-trigger btn btn-primary btn-lg btn-block">Sign up</a> 

JS:

$('.bb-trigger').on("click", function(e) { 
bootbox.prompt("<strong>Email address</strong>Enter email address where the report should be send to : ", function(result) {     
    if (result) { 
     // Example.show("email: <b>"+result+"</b>");  
     console.log("NikoS"); 
    } 
}); 

});

工作有細