2016-07-20 7 views
0

$("demo").css("border", "1px solid #FFF");はなぜ機能しませんか?機能の他のすべての部分は動作していますが、その部分は動作していません。クラス "デモ"は "page1.html"からのレギュラーです。Jqueryがクラスのすべての罫線を変更します

<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> 
+0

「デモ」はクラスですか?もしそうなら、 '$("。demo ")'で指定する必要があります。 –

+0

私はスクリプトが別のものによって上書きされていることを知りました。私はそれが別の色に行く前に数秒で白くなるのがわかります。その理由は何でしょうか? ページの最後です! – Carl

答えて

1
$("demo") 

ヒット全て<デモ>タグの場合には、彼らは私がいないと確信している、存在しています。あなたは紛失しています

クラスまたはID 'デモ'の要素をヒットする。

これに加えて、load()は非同期関数なので、ページがロードされる前にcss()コールが起動されるため、エレメントスタイルは変更されません。あなたはこの方法を呼び出す()負荷()とCSSを交換SHOLD:

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

})

は、だから、コンテンツがサーバからロードされるまで待つようにCSSのassignementを強制します。

+0

いいえ、動作しませんでした。縁は白くならない。 – Carl

+0

load-functionを使用していますが、.demoはpage1.html内にあります(私のインデックスに含まれています) – Carl

+0

これは、HTMLサーバー側をロードしているか、ロードしているかによって大きく異なりますそれはdinamically。あなたがその.css()呼び出しの後にdinamicallyロードしている場合、動作しません。 – Sergeon

2

完全停止していません。 $(".demo").css("border", "1px solid #FFF");

+0

いいえ、動作しませんでした。 – Carl

+0

エラーは表示されませんが、境界線は白くなりません。 – Carl

関連する問題