简体   繁体   English

Java 脚本验证

[英]Java Script validation

Am validating a form for empty check.我正在验证一张空支票的表格。

All fields works fine.所有领域都工作正常。

I have a dropdown when i select some value from dropdown some fields will be disabled.当我 select 下拉列表中的某些值将被禁用时,我有一个下拉列表。 onchanging the dropdown value someother fields will be disabled.在更改下拉值时,其他字段将被禁用。

Now am struck in validating the fields which are getting disabled and enabled.现在我在验证被禁用和启用的字段时感到震惊。

if((document.form1.varAuctionTime.disabled = false) && (document.form1.varAuctionTime.value == ""))   

I used above code but it is enabling the fields.我使用了上面的代码,但它正在启用这些字段。

can anybody help me out.谁能帮帮我。

You are using = (assignment) where you want == (comparison)你在你想要的地方使用= (赋值) == (比较)

I upvoted Quentin's answer.我赞成昆汀的回答。

document.form1.varAuctionTime.disabled = false uses the assignment operator, which sets the value of disabled to false document.form1.varAuctionTime.disabled = false使用赋值运算符,将disabled的值设置为false

document.form1.varAuctionTime.disabled == false will do a comparison and will return true if the value of disabled is false (or technically, if the value is 0 or an empty string) document.form1.varAuctionTime.disabled == false将进行比较,如果 disabled 的值为false将返回true (或者技术上,如果值为0或空字符串)

document.form1.varAuctionTime.disabled === false will only return true if the value is false and not if it is 0 or an empty string. document.form1.varAuctionTime.disabled === false将仅在值为false时返回 true,而不是在值为0或空字符串时返回。 This is probably not required as AFAIK the disabled property will always return a boolean.这可能不是必需的,因为 AFAIK disabled的属性将始终返回 boolean。

To give you a few alternatives that you may prefer;为您提供一些您可能喜欢的替代方案; since the comparison operators return booleans, and the disabled property is a boolean anyway, you could just do the following因为比较运算符返回布尔值,并且disabled属性无论如何都是 boolean,所以您可以执行以下操作

if(!document.form1.varAuctionTime.disabled && !document.form1.varAuctionTime.value)

replace代替

document.form1.varAuctionTime.disabled = false document.form1.varAuctionTime.disabled = false

with

document.form1.varAuctionTime.disabled == false document.form1.varAuctionTime.disabled == false

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

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