【发布时间】:2019-07-29 12:42:14
【问题描述】:
我正在使用 jscolor 并尝试将用户选择的颜色从 test1.php 传递到 test2.php,然后转换为 rgb。不知何故无法正常工作。
如果我将表单帖子更改为test1.php,它会检索到正确的值,但在更改action="test2.php" 时则无法正常工作。
test1.php:
<script>
function update(jscolor) {
// 'jscolor' instance can be used as a string
document.getElementById('rect').style.backgroundColor = '#' + jscolor
}
</script>
<form action="test2.php" method="post">
Select you favorite color:
<input name="clr1" class="jscolor {onFineChange:'update(this)'}">
<input type="submit" name="submit">
</form>
<p id="rect" style="border:1px solid gray; width:161px; height:100px;">
<?php
session_start();
if(isset($_POST['clr1'])) {
$selected_color = $_POST['clr1'];
$_SESSION['bgcolors'] = $selected_color;
}
?>
test2.php:
session_start();
$selected_color = $_SESSION['bgcolors'];
echo $selected_color;
echo "<br>";
list($r, $g, $b) = array_map('hexdec', str_split($selected_color, 2));
$bgcolor2 = $r . "," . $g . "," .$b;
echo $bgcolor2;
【问题讨论】:
标签: javascript php jscolor