[英]return false has to stop execution in java script
我正在比较日期和日期在java脚本中如果值为false我返回false但程序正在执行。
我的java脚本代码
function Noofdays() {
var total= document.getElementById('ctl00_MainContent_Txtabc');
var days = document.getElementById('ctl00_MainContent_ddldays');
if (total= days) {
alert("same");
return true;
}
else {
alert("not same");
return false;
}
}
我在保存按钮中从c#代码调用此函数,
ScriptManager.RegisterStartupScript(this, GetType(), "FromDateSample", "Noofdays();", true);
我在保存按钮中有一个客户端点击事件。
if语句的条件是将days
数值分配给total
。 要比较这两个值,您需要使用比较运算符( ==
或===
)。
您可能想要转换为数字
var total= +document.getElementById('ctl00_MainContent_Txtabc').value; var days = +document.getElementById('ctl00_MainContent_ddldays').value; if (total==days) {
在函数调用之前使用return 。
ScriptManager.RegisterStartupScript(this,GetType(),“FromDateSample”,“ return Noofdays();”,true);
按钮:
<asp:Button ... OnClientClick =“ return Noofdays();”>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.