我是一個新手,jQuery
,我試圖創建具有不同顏色的頁面,當我們點擊任何一個,它改變了導航欄和頁腳和背景顏色使用AJAX來這裏更新MYSQL
database.So是我jQuery
代碼:jQuery的不是它的組件工作是彩色動畫和Ajax
$(document).ready(function() {
$('[name="personal_theme_color"]').click(function() {
var a = $('[name="personal_theme_color"]').val();
switch (a) {
case "pink":
var b = "#e91e63";
break;
case "purple":
b = "#9c27b0";
break;
case "deep-purple":
b = "#673ab7";
break;
case "indigo":
b = "#3f51b5";
break;
case "light-blue":
b = "#03a9f4";
break;
case "cyan":
b = "#00bcd4";
break;
case "green":
b = "#4caf50";
break;
case "light-green":
b = "#8bc34a";
break;
case "lime":
b = "#cddc39";
break;
case "yellow":
b = "#ffeb3b";
break;
case "amber":
b = "#ffc107";
break;
case "orange":
b = "#ff9800";
break;
case "deep-orange":
b = "#ff5722";
break;
case "brown":
b = "#9e9e9e";
break;
case "grey":
b = "#9e9e9e";
}
$(".nav-wrapper").animate({
backgroundColor: b
});
$("footer").animate({
backgroundColor: b
});
$.ajax({
type: "POST",
url: "jsp/update_user_theme.php",
data: "theme=" + a,
cache: false,
success: function(a) {
alert("Updated successfully");
}
});
});
});
所以這是我的代碼。我不知道它有什麼問題,但我真的需要幫助。 注:我已經包括了jQuery
顏色動畫插件
而且我PHP
代碼:
<?php
require_once('http://' . $_SERVER['SERVER_NAME'] . '/sp/conn.php');
$theme = mysqli_fetch_array($dbc, trim(htmlentities($_POST['theme'])));
// Now update query
$query = "UPDATE user set theme = '$themecolor', hex2 = '$hex' WHERE id = '" . $_COOKIE['id'] . "'";
mysqli_query($dbc, $query);
?>
附:我真的很感激在PHP
代碼本身的一些幫助過,尤其是對使它SQL
注塑證明。預先感謝您 祝您有美好的一天
編輯: HTML。我用foreach
循環從數組中獲取這些值。但是這個html是硬編碼的(從鉻的view-source:
)。見類值標籤和輸入標籤:
<label class="personal_theme_label">
<div class="style_personal_img pink waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
pink
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="pink" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img purple waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
purple
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="purple" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img deep-purple waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
deep-purple
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="deep-purple" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img indigo waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
indigo
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="indigo" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img blue waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
blue
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="blue" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img light-blue waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
light-blue
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="light-blue" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img cyan waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
cyan
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="cyan" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img green waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
green
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="green" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img light-green waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
light-green
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="light-green" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img lime waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
lime
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="lime" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img yellow waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
yellow
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="yellow" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img amber waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
amber
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="amber" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img orange waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
orange
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="orange" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img deep-orange waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
deep-orange
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="deep-orange" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img brown waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
brown
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="brown" />
</label>
<label class="personal_theme_label">
<div class="style_personal_img grey waves-effect waves-light z-depth-1">
<br>
<br>
<font style="text-transform: capitalize;">
grey
</font>
</div>
<input name="personal_theme_color" type="radio" class="with-gap" id="test1" value="grey" />
</label>
而且,我的網頁截圖的差異和: This is how my page looks
,這是什麼元素的HTML:'[NAME = \ 「personal_theme_color \」 ]'? – Rasclatt
提供點擊實際選擇正確的元件,這條線變化'變種ptcval = $(本).VAL();'代替'變種ptcval = $( 「[NAME = \」 personal_theme_color \ 「]」)VAL。 ();' – Rasclatt
做點擊功能火嗎? – gypsyCoder