Javascript 错误:左侧无效分配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19015213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript error : invalid assignment left-hand side
提问by Scott Holtzman
Using javascript in Acrobat XI. For some reason, I keep getting the following error:
在 Acrobat XI 中使用 javascript。出于某种原因,我不断收到以下错误:
invalid assignment left-hand side at 9: line 10
invalid assignment left-hand side at 9: line 10
My code is pretty simple and looks spot on AFAICT. Please review and tell me I'm not crazy. (Or tell me I am, but you have a solution :))
我的代码非常简单,在 AFAICT 上看起来很合适。请检查并告诉我我没有疯。(或者告诉我我是,但你有一个解决方案:))
function jsNetworkAccount()
{
// Get a reference to each check box
var f1 = getField("cbNetworkNotNeeded");
var f2 = getField("cbNetwork");
var f3 = getField("cbEmailAccount");
if (event.target === f1 && event.value = "On") {
f2.value = "Off";
f3.value = "Off";
return;
}
if (event.target === f2 || event.target === f3 && event.value = "On") {
f1.value = "Off"
return;
}
}
回答by ComFreek
Two equal signs:
两个等号:
if (event.target === f1 && event.value = "On") {
// -------------------------------------^^
if (event.target === f1 && event.value === "On") {
if (event.target === f2 || event.target === f3 && event.value = "On") {
// ------------------------------------------------------------^^
if (event.target === f2 || event.target === f3 && event.value === "On") {
I used three equal signs in my code above for keeping your coding style consistent.
我在上面的代码中使用了三个等号来保持你的编码风格一致。
As vol7ron suggested, you should also add parentheses in your IF statements. This greatly improves readability in my opinion.
正如 vol7ron 所建议的,您还应该在 IF 语句中添加括号。在我看来,这大大提高了可读性。