gpt4 book ai didi

javascript - 将 jscolor 从一个 php 页面传递到另一个

转载 作者:行者123 更新时间:2023-11-30 06:14:09 24 4
gpt4 key购买 nike

我正在使用 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;

最佳答案

session_start这段代码之后加入test2.php

 if (isset($_POST['clr1'])) { 
$selected_color = $_POST['clr1'];
$_SESSION['bgcolors'] = $selected_color;
}

关于javascript - 将 jscolor 从一个 php 页面传递到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57254114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com