我对JQuery非常陌生,实际上这是我写过的第一个脚本。下面简单地找到所有具有类“TestDIV”的DIV,然后在发现其中的输入时执行一些操作。在JQuery中更改borderColor的问题
除了borderColor,它仍然是我最初设置的颜色。有人对此有何看法?我也非常欢迎有关如何改进我的代码的提示。
function hideAndShowJQ(show) {
var hideColor = "#DFDFDF";
//Find DIVs and modify styling
var div = $('div.TestDIV'); //Find relevant divs
div.css('color', (show) ? "" : hideColor) //Change text colour
.find(':input').attr("disabled", !show) //Disable any inputs
.attr("borderColor", "red") //Change border colour of inputs
.attr("value", ""); //Clear any existing input text
}
不要紧,无论是`borderColor`或`边界color`。两者都可以工作。只有当你传递一个对象到`css`时,如果你使用非字符串键,它必须是`borderColor`。 – 2011-01-20 10:49:33
@Felix Kling:真的吗?我总是认为它的工作方式与变量类似(因为它们不会被字符串内插)。不过,我不知道我为什么这么想。谢谢! – 2011-01-20 10:51:47