繁体   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