我需要使用小于或大于比较两个值,但它不能正常工作。下面我的代码。JavaScript比较运算符不工作
//JAVASCRIPT
<script type="text/javascript">
function validform()
{
var balanvar = document.myform.balance.value,
currntvar = document.myform.currnt.value;
if(currntvar == "") { document.myform.currnt.focus(); document.getElementById("curntid").style.borderColor = "red"; return false; } // Must be filled error
if(currntvar > balanvar) { document.myform.currnt.focus(); document.getElementById("curntid").style.borderColor = "red"; return false; } else { document.getElementById("curntid").style.borderColor = "green"; } // Maximum value error
}
</script>
//HTML
<form name="myform" method="post" action="">
<input type="text" name="balance" id="balanceid" value="12000"/>
<input type="text" name="currnt" id="curntid"/>
<input type="submit" name="submit" value="Proceed" onclick="return validform();"/>
</form>
我想是的,我要进入比“currnt”文本框中输入“平衡”值少,如果我进入最大值比较“平衡”文本框中的意思是,抛出的错误消息。
问题是,点击继续而没有填充“currnt”时显示错误。当在“currnt”中输入值15000时表示其显示错误。但是在“currnt”中输入100000的值意味着它不给出错误。我不知道这是什么错误。请帮帮我。
可能重复http://stackoverflow.com/questions/6395777/basic-javascript-数学文本字段)。另见http://stackoverflow.com/questions/20604138/how-to-get-an-input-value-dynamically-and-perform-arithmetic-operations-using-ja,http://stackoverflow.com/questions/ 23258696/instantiate-a-variable-out-text-field-value-in-javascript,http://stackoverflow.com/questions/18614374/plus-arithmetic-operation等 – 2014-11-24 13:21:27
问及多次回答。但实际上你甚至不需要为此而来到SO。自己找到这个问题的答案并不比简单地停止所讨论的调试器,观察'document.myform.balance.value'并注意它是一个字符串困难得多。 – 2014-11-24 13:23:24
@torazaburo看到我只知道js的基本知识,我试过但无法识别错误。这就是为什么我在这里问。 – Piruthvi 2014-11-24 14:50:02