簡體   English   中英

包括Jade中用於按鈕單擊的Javascript

[英]Including Javascript for button click in Jade

我在使用Node.js,Bootstrap和Jade檢測按鈕單擊時遇到問題。

我有以下Jade代碼,但沒有從onclick方法中看到日志,並且按鈕沒有變化。 因此,該方法永遠不會被調用。

 extends layout block content .jumbotron .container h1= title p Enter the url of the file to be sent form#formInputURL(name="chooser",method="post",action="/chooser",) input#inputURL(type="text", placeholder="insert url", name="chooseurl") button#btnSubmit(type="submit") submit p .btn-group(data-toggle='buttons') label.btn.btn-primary.active input#option1(type='checkbox', autocomplete='off', checked='') | Radio 1 (preselected) | label.btn.btn-primary input#option2(type='checkbox', autocomplete='off') | Radio 2 | label.btn.btn-primary input#option3(type='checkbox', autocomplete='off') | Radio 3 script. $('#option2').on('click', function () { console.log("clicked") $(this).button('toggle') }) 

您的代碼運行正常,

確保您單擊的是正確的元素(復選框)。

看一下這個例子:

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="jumbotron"> <div class="container"> <h1></h1> <p>Enter the url of the file to be sent</p> <form id="formInputURL" name="chooser" method="post" action="/chooser"> <input id="inputURL" type="text" placeholder="insert url" name="chooseurl" /> <button id="btnSubmit" type="submit">submit</button> <p></p> <div data-toggle="buttons" class="btn-group"> <label class="btn btn-primary active"> <input id="option1" type="checkbox" autocomplete="off" checked="" /> Radio 1 (preselected) </label> <label class="btn btn-primary"> <input id="option2" type="checkbox" autocomplete="off" /> Radio 2 </label> <label class="btn btn-primary"> <input id="option3" type="checkbox" autocomplete="off" /> Radio 3 </label> </div> </form> </div> </div> <script> $('#option2').on('click', function() { alert("clicked") }) </script> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM