简体   繁体   English

HTML / Javascript 函数未调用

[英]HTML / Javascript Function Not Calling

This code that I wrote is meant to call the calculateInterest function and return false.我编写的这段代码旨在调用calculateInterest函数并返回false。 However, the page does not appear to call the function or return false.但是,页面似乎没有调用该函数或返回 false。 Thank you for the help.感谢您的帮助。

HTML HTML

<form onsubmit="return calculateInterest(); return false;"  id="interest_calc" name="interest_calc"  method = "get";> 
  ...
  <input type="submit" id="calculate" value="Calculate">
  <input type="button" id="calculate" value="test" onclick="return calculateInterest();">
</form> 

JS JS

var $ = function (id) 
{
  return document.getElementById(id);
};//DOM function
...

//DEBUG alert (iPercentage);
var calculateInterest; = function () 
{
  alert ("function called");
  return false
};

Remove the unnecessary ;删除不必要的; on script .And no need a return false on submit function call in html.Because its already there in calculateinterest function在脚本上。在html中submit函数调用时不需要return false 。因为它已经存在于calculateinterest函数中

 var $ = function(id) { return document.getElementById(id); } var calculateInterest = function() { alert("function called"); return false };
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form onsubmit="return calculateInterest()" id="interest_calc" name="interest_calc" method="get" ;> ... <input type="submit" id="calculate" value="Calculate"> <input type="button" id="calculate" value="test" onclick="return calculateInterest();"> </form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM