对为什么js函数中的相同方法有不同的结果感到困惑

confused as to why same methods in js function have different results

本文关键字:结果 方法 函数 为什么 js      更新时间:2023-09-26

非常困惑为什么这样做:

cPassword.style.borderColor = matchCol;

但这不会:

submitButton.style.backgroundColor = #a2bb33;

cPassword 定义如下:

<input type="password" name="cPassword" class="iBox"  id="cPassword" onkeyup="passwordValidation()" placeholder="confirm it!" autocomplete="off">

此处定义了"提交"按钮:

<input type="submit" id="submitButton" value="submit" disabled="disabled" onmouseout="SubmitToolTipHide()" onmouseover="SubmitToolTip()">

除非我很愚蠢,否则它们以相同的方式定义,因此上面的代码应该可以工作。 但事实并非如此。 事实上,由于某种奇怪的原因,它完全禁用了 AngularJS 的工作

#a2bb33不是有效的JavaScript语法。您必须将颜色值放在字符串中

submitButton.style.backgroundColor = "#a2bb33";

您的第一个示例之所以有效matchCol是因为它可以正确地解析为标识符(变量)。当然,这个变量也必须存在。