簡體   English   中英

HTML 按鈕不適用於內聯 javascript

[英]HTML Button not working with inline javascript

我創建了一個內聯 javascript 來測試按鈕,但單擊時該按鈕不起作用。

我想也許 js 代碼是錯誤的,但我用一個簡單的警報測試了按鈕,但它仍然無法正常工作,你能幫忙嗎? 這是 HTML / 和示例 js 腳本。

 function calcEquation() { alert("hello");
 <form id="form-ckd" method="post"> <div id="ckd-calc"> <div class="card"> <div class="card-header py-3"> <h6 class="m-0 font-weight-bold text-primary">CKD calculator</h6> </div> <div class="card-body"> <p>Sex of patient:</p> <div> <label class="radio-inline"> <input type="radio" name="sex-ckd" value="m"> Male </label> <label class="radio-inline"> <input type="radio" name="sex-ckd" value="f"> Female </label> <br /><br /> <p>Ethnicity:</p> <label class="radio-inline"> <input type="radio" name="race-ckd" value="b"> Black </label> <label class="radio-inline"> <input type="radio" name="race-ckd" value="o"> Other </label> <br /><br /> <p>Age of patient (years):</p> <input type="number" min="1" max="120" name="age-ckd" /> <br /><br /> <p>Serum creatinine (micromol/L):</p> <input type="number" min="1" max="120" name="serum-ckd" /> <br /> </div> <br /> <hr /> <div id="ckd-result"> <h5 id="outs-ckd"></h5> <p>Glomerular Filtration Rate by the MDRD Equation: <a href="https://www.mdcalc.com/mdrd-gfr-equation#evidence" style="color:white;"><u> mdcalc website</u></a></p> </div> <button type="button" class="btn btn-primary" onclick="calcEquation();">Calculate</button> <button type="button" class="btn btn-danger" onclick="popup.hideEquationFormPopup();">Close</button> <button type="reset" class="btn btn-primary" onclick="resetCKD();">Reset</button> </div> </div> </div> </form>

  <script type=text/javascript>
        function calcEquation(){
          alert("hello");
  </script>

我想你最后忘了用}關閉 function 。

那是因為您在 function calcEquation:) 上遺漏了一個閉合的花括號。

 <script type=text/javascript> function calcEquation(){ alert("hello");} </script> <form id="form-ckd" method="post"> <div id="ckd-calc"> <div class="card"> <div class="card-header py-3"> <h6 class="m-0 font-weight-bold text-primary">CKD calculator</h6> </div> <div class="card-body"> <p>Sex of patient:</p> <div> <label class="radio-inline"> <input type="radio" name="sex-ckd" value="m"> Male </label> <label class="radio-inline"> <input type="radio" name="sex-ckd" value="f"> Female </label> <br /><br /> <p>Ethnicity:</p> <label class="radio-inline"> <input type="radio" name="race-ckd" value="b"> Black </label> <label class="radio-inline"> <input type="radio" name="race-ckd" value="o"> Other </label> <br /><br /> <p>Age of patient (years):</p> <input type="number" min="1" max="120" name="age-ckd" /> <br /><br /> <p>Serum creatinine (micromol/L):</p> <input type="number" min="1" max="120" name="serum-ckd" /> <br /> </div> <br /> <hr /> <div id="ckd-result"> <h5 id="outs-ckd" ></h5> <p >Glomerular Filtration Rate by the MDRD Equation: <a href="https://www.mdcalc.com/mdrd-gfr-equation#evidence" style="color:white;"><u> mdcalc website</u></a></p> </div> <button type="button" class="btn btn-primary" onclick="calcEquation();">Calculate</button> <button type="button" class="btn btn-danger" onclick="popup.hideEquationFormPopup();">Close</button> <button type="reset" class="btn btn-primary" onclick="resetCKD();">Reset</button> </div> </div> </div> </form>

暫無
暫無

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

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