所以我一直在使用該網站的答案,但現在我需要一些幫助,所以在這裏。拿着onclick jquery頁面重裝後
我使用jquery在按鈕上創建了一堆onclick事件,並使用它們來動態更改我網站上的CSS。我遇到的問題是我希望用戶在重新加載頁面或調用第二個頁面時選擇顏色和字體大小設置。
編輯:所選的背景顏色現在發送到URL,並將保留重新加載的值,但如果我點擊第二個選項第一個選項被禁用,第二個被啓用,但第一個屬性仍然顯示在URL我需要有背景顏色一個字體顏色一個字體大小至少四個可能點擊一個又一個的線hieght
任何幫助我理解
這些按鈕
<div id="bc">
Background Colour
<button id="bcyellow">yellow</button>
<button id="bcblue">blue</button>
<button id="bcblack">black</button>
<button id="bcwhite">white</button>
</div>
<div id="tc">
Text Colour
<button id="tcyellow">yellow</button>
<button id="tcblue">blue</button>
<button id="tcblack">black</button>
<button id="tcwhite">white</button>
</div>
<div id="fs">
Font Size
<button id="fsdown">Default</button>
<button id="fsup">Big</button>
</div>
<div id="lh">
Line Height
<button id="lhdown">Default</button>
<button id="lhup">Wide</button>
</div>
這個 是jquery
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
$(document).ready(function(){
//change background colour to yellow
$(function(){
$("#bcyellow").click(function(){ window.location = document.URL+"?background-color=yellow"; });
switch(getParameterByName("background-color")){
case "yellow" :
$("body").css("background-color","rgba(247, 233, 107, 1)");
break;
default :
//your default color
break;
}
});
//change background colour to blue
$(function(){
$("#bcblue").click(function(){ window.location = document.URL+"?background-color=blue"; });
switch(getParameterByName("background-color")){
case "blue" :
$("body").css("background-color","rgba(110, 165, 236, 1)");
break;
default :
//your default color
break;
}
});
//change background colour to green
$(function(){
$("#bcgreen").click(function(){ window.location = document.URL+"?background-color=green"; });
switch(getParameterByName("background-color")){
case "green" :
$("body").css("background-color","rgba(156, 255, 174, 1)");
break;
default :
//your default color
break;
}
});
//change background colour to pink
$(function(){
$("#bcpink").click(function(){ window.location = document.URL+"?background-color=pink"; });
switch(getParameterByName("background-color")){
case "pink" :
$("body").css("background-color","rgba(245, 175, 247, 1)");
break;
default :
//your default color
break;
}
});
//change background colour to black
$(function(){
$("#bcblack").click(function(){ window.location = document.URL+"?background-color=black"; });
switch(getParameterByName("background-color")){
case "black" :
$("body").css("background-color","rgba(0, 0, 0, 1)");
break;
default :
//your default color
break;
}
});
//change background colour to white
$(function(){
$("#bcwhite").click(function(){ window.location = document.URL+"?background-color=white"; });
switch(getParameterByName("background-color")){
case "white" :
$("body").css("background-color","rgba(255, 255, 255, 1)");
break;
default :
//your default color
break;
}
});
//change text colour to green
$(function(){
$('#tcgreen').click(function(){ window.location = document.URL+"?color=green"; });
switch(getParameterByName("color")){
case "green" :
$('body').css("color", "rgba(0, 150, 0, 1)") ;
break;
default :
//your default color
break;
}
});
//change text colour to blue
$(function(){
$('#tcblue').click(function(){ window.location = document.URL+"?color=blue"; });
switch(getParameterByName("color")){
case "blue" :
$('body').css("color", "rgba(0, 0, 171, 0.9)");
break;
default :
//your default color
break;
}
});
//change text colour to black
$(function(){
$('#tcblack').click(function(){ window.location = document.URL+"?color=black"; });
switch(getParameterByName("color")){
case "black" :
$('body').css('color', 'rgba(0, 0, 0, 1)');
break;
default :
//your default color
break;
}
});
//change text colour to white
$(function(){
$('#tcwhite').click(function(){ window.location = document.URL+"?color=white"; });
switch(getParameterByName("color")){
case "white" :
$('body').css('color', 'rgba(255, 255, 255, 1)');
break;
default :
//your default color
break;
}
});
//change text size increment
$(function(){
$('#fsup').click(function(){ window.location = document.URL+"?font-size3em"; });
switch(getParameterByName("font-size")){
case "3em" :
$("body").css("font-size","3em");
break;
default :
//your default size
break;
}
});
//reset text size
$(function(){
$('#fsdown').click(function(){ window.location = document.URL+"?font-size=1em"; });
switch(getParameterByName("font-size")){
case "1em" :
$("body").css("font-size","1em");
break;
default :
//your default font-size
break;
}
});
//change line height to wide
$(function(){
$('#lhup').click(function(){ window.location = document.URL+"?line-height=wide"; });
switch(getParameterByName("line-height")){
case "wide" :
$("body").css("line-height","1.5");
break;
default :
//your default line-height
break;
}
});
//reset line height
$(function(){
$('#lhdown').click(function(){ window.location = document.URL+"?line-height=default"; });
switch(getParameterByName("line-height")){
case "default" :
$("body").css("line-height","1");
break;
default :
//your default line-height
break;
}
});
});
以及第一件事就是刪除所有文件準備功能,只是有一個把所有的點擊中......其冗餘碼的跑 –
你真的應該考慮使用類研究所的時候吃更多的時間ead並將此代碼重構爲只有一個點擊處理程序。 –
好吧,我可以做這些事情感謝您的快速回應 – Vin