简体   繁体   English

如何禁用带有 javascript onchange 功能的表单?

[英]How can I disable a form with javascript onchange function?

I'm trying to disable a form in a JSP just when two conditions become true.我试图在两个条件成立时禁用 JSP 中的表单。 I've tried a var variable set false so when my if-else condition becomes true it becomes true.我尝试了一个 var 变量设置为 false,所以当我的 if-else 条件变为 true 时它变为 true。 But it is not working.但它不起作用。

Here is my code.这是我的代码。 (not sure if it can help but I'm using eclipse) (不确定它是否有帮助,但我正在使用 eclipse)

var disabled=false;

then I've created the function然后我创建了函数

function isDisable(){
    if($("#idCost").val() == 1 && $("#IdBasket").val() == "3"){
        disabled=true;
    }
}

and then set in the form field然后在表单域中设置

< disabled="false"/>

What am I doing wrong?我究竟做错了什么?

Thanks for helping谢谢你的帮助

It looks like your code is in JavaScript and not Java, even though you say you are writing a JSP.看起来您的代码使用的是 JavaScript 而不是 Java,即使您说您正在编写 JSP。

Your JS code compare one return to a Number (val() == 1) and another to a String val() == "3".您的 JS 代码将一个 return 与 Number (val() == 1) 和另一个与 String val() == "3" 进行比较。 Did you try making them both the same?你有没有尝试让它们一样? If .val() is returning strings, then they should both compare to strings.如果 .val() 返回字符串,那么它们都应该与字符串进行比较。 If .val() is returning numbers, then they should both compare to numbers.如果 .val() 返回数字,那么它们都应该与数字进行比较。

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

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