我想知道是否可以在onchange事件中編輯css屬性。在onchange事件中更新css
我的HTML +腳本
<div class="Content">
<input id="ColorSlider" type="range" min="0" max="360" value="25" onchange="showValue(this.value)"/>
<div id="ColorViewer">
Color value = 25
</div>
<script>
function showValue(newValue){
document.getElementById("ColorViewer").innerHTML= "Color value = " + newValue;
//something here that sends the value to the css file
}
而我的CSS,這是目前從不同的PHP文件
<?php
header('Content-type: text/css');
session_start();
$CssBorder = $_SESSION['CssBorder'];
$CssH1BackgroundColor = $_SESSION['CssH1BackgroundColor'];
?>
接收會話變量是否有可能發送一個變量(也許通過PHP會話)到CSS文件。並更改HTML邊框的顏色?
爲了清除目的,我希望我的css文件是外部的。
@RUJordan可以,只需要創建一個PHP文件改變顏色,稱之爲頭說這是CSS。然後將其用作變量。 <?php echo $ CssH1BgroundgroundColor?> –