简体   繁体   English

jQuery更改类的所有边界

[英]Jquery change all borders on classes

Why is not $( "demo" ).css("border", "1px solid #FFF"); 为什么不是$( "demo" ).css("border", "1px solid #FFF"); working? 工作吗 Every other part of the function is working, but not that one. 该功能的所有其他部分都在工作,但没有工作。 The class "demo" is a regular from "page1.html". 类“ demo”是“ page1.html”中的常规。

<script>
var button = 0;
var activecolor = 0;
function pressbutton(a){
button = a;
var color1 = "#46B29D";
var color2 = "#F0CA4D";
var color3 = "#E37B40";
if (button === 1) {
activecolor = color1;
document.getElementById("button1").className = "activemenubutton";
document.getElementById("button2").className = "menubutton";
document.getElementById("button3").className = "menubutton";
} else if (button === 2){
activecolor = color2;
document.getElementById("button1").className = "menubutton";
document.getElementById("button2").className = "activemenubutton";
document.getElementById("button3").className = "menubutton";
} else if (button === 3){
activecolor = color3;
document.getElementById("button1").className = "menubutton";
document.getElementById("button2").className = "menubutton";
document.getElementById("button3").className = "activemenubutton";
}

document.getElementById("textholder").style.borderTop = "1px solid " + activecolor;
document.getElementById("textholder").style.borderBottom = "1px solid " + activecolor;
document.getElementById("textholder").style.color= activecolor;


$("#textholder").load("Page" + a + ".html");
$( "demo" ).css("border", "1px solid #FFF");

} //end of function

</script>

You're missing a full stop. 您错过了句号。 $( ".demo" ).css("border", "1px solid #FFF");

$("demo")

hits all < demo > tags, in case they exists, which I'm sure don't. 击中所有<demo>标记(如果它们存在的话),我确定不会。 You're missing 你不见了

$(".demo") or $("#demo") 

to hit elements with class or id 'demo'. 击中类别或ID为“演示”的元素。

On top of that, load() is an asynchronous function, so the css() call will usually fire before the page is loaded, therefore not modifying your element styles. 最重要的是,load()是一个异步函数,因此css()调用通常会在页面加载之前触发,因此不会修改元素样式。 You shold replace the load() and css() calls this way: 您可以通过以下方式替换load()和css()调用:

$("#placeholder").load("Page" + a + ".html" , function(){
   $(".demo").css('border' , '1px solid #FFF');

}) })

So you force the css assignement to wait until the content is loaded from the server. 因此,您可以强制CSS分配等待,直到从服务器加载内容为止。

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

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