- 1、jsp引用css,設置的body樣式被瀏覽器禁用?
- 2、如何在Java中的Jsp頁面中更換頁面樣式?
- 3、html jsp頁面菜單循環更改樣式問題?
- 4、JSP的Style樣式不起作用
不是被禁用了,是被覆蓋了。
可以通過改變css的樣式的順序來修改或者粗暴一點,直接寫成body{margin:55px 10px 10px 10px !importent;background-color:blue !importent;}
Jsp頁面中更換頁面樣式可以通過js來動態設置。
完整的樣式更改代碼如下:
html
head
style type=”text/css”
#test2a{
position: absolute;
left: 0px;
width: 50px;
height: 50px;
background-color: green;
border: 4px solid black;
}
#test2b{
position: absolute;
left: 55px;
width: 50px;
height: 50px;
background-color: yellow;
margin: 4px;
}
/style
/head
body
!– test1 —
Swap left positions function with styles defined inline.
a href=”javascript:test1();”Test 1/abr
div class=”container”
div id=”test1a” style=”position: absolute;left: 0px;width: 50px; height: 50px;background-color: green;border: 4px solid black;”/div
div id=”test1b” style=”position: absolute;left: 55px;width: 50px; height: 50px;background-color: yellow;margin: 4px;”/div
/div
script type=”text/javascript”
function test1(){
var a = document.getElementById(“test1a”);
var b = document.getElementById(“test1b”);
alert(a.style.left + ” – ” + b.style.left);
a.style.left = (a.style.left == “0px”)? “55px” : “0px”;
b.style.left = (b.style.left == “0px”)? “55px” : “0px”;
}
/script
!– end test 1 —
!– test2 —
div id=”moveDownThePage” style=”position: relative;top: 70px;”
Identical function with styles defined in stylesheet.
a href=”javascript:test2();”Test 2/abr
div class=”container”
div id=”test2a”/div
div id=”test2b”/div
/div
/div
script type=”text/javascript”
function test2(){
var a = document.getElementById(“test2a”);
var b = document.getElementById(“test2b”);
alert(a.style.left + ” – ” + b.style.left);
a.style.left = (a.style.left == “0px”)? “55px” : “0px”;
b.style.left = (b.style.left == “0px”)? “55px” : “0px”;
}
/script
/body
/html
寫js代碼
1,for循環遍歷菜單
2默認菜單1藍色背景,其他的無色
3.鼠標點擊觸發事件,根據index標號來確定點擊的是哪一個菜單,選中的菜單變藍色(index這個屬性在元素裡面一般沒有,但是在js裡面可以加上)
思路大體這樣,下面給你參考代碼:
效果:
可能是你瀏覽器版本的問題啊!
有些屬性是不支持的!
建議你用ID選擇器#id名
或者class選擇器.類名
這樣就一定不會出錯啊!
原創文章,作者:簡單一點,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/127311.html