gpt4 book ai didi

javascript - 执行 javascript 代码并根据 $id=$_GET ['id' 检查单选按钮];当页面加载时

转载 作者:行者123 更新时间:2023-11-28 10:56:59 25 4
gpt4 key购买 nike

请帮我一个...当页面加载时,如果$Id=pack单选按钮pack被选中并且DIV PACK Display:Block;

如果 $id =ind ,则单选按钮 ind 为选中状态,并且 DIV ind Display:Block;

<?PHP
$id=$_GET['id'];
?>
<!DOCTYPE>
<html>
<body>

<label>Package</label>
<input type="radio" name="package" value="pack"
<?php if($id=='pack')
{
echo"checked";
echo"<script type=\"text/javascript\">";
echo"document.getElementById(\"package\").style.display=\"block\"";
echo"</script>";
} ?>
>

<label>Individual</label>
<input type="radio" name="package" value="ind"
<?php if($id=='ind')
{
echo"checked";
echo"<script type=\"text/javascript\">";
echo"document.getElementById(\"individual\").style.display=\"block\"";
echo"</script>";
} ?>
>

<div id="package" style=" display:none; height:100px; background-color:#a00; color:#fff;">
Display this div if PACKAGE is checked
</div>

<div id="individual" style=" display:none; height:100px; background-color:#a00; color:#fff;">
Display this div if INDIVIDUAL is checked
</div>
</body>
</html>

最佳答案

试试这个:

<?PHP
$id=$_GET['id'];
?>
<!DOCTYPE>
<html>
<body>

<label>Package</label>
<input type="radio" name="package" value="pack" >



<label>Individual</label>
<input type="radio" name="package" value="ind" >



<div id="package" style=" display:none; height:100px; background-color:#a00; color:#fff;">
Display this div if PACKAGE is checked
</div>

<div id="individual" style=" display:none; height:100px; background-color:#a00; color:#fff;">
Display this div if INDIVIDUAL is checked
</div>
<?php if($id=='pack')
{
echo"checked";
echo"<script type=\"text/javascript\">";
echo"document.getElementById(\"package\").style.display=\"block\"";
echo"</script>";
} ?>
<?php if($id=='ind')
{
echo"checked";
echo"<script type=\"text/javascript\">";
echo"document.getElementById(\"individual\").style.display=\"block\"";
echo"</script>";
} ?>
</body>
</html>

关于javascript - 执行 javascript 代码并根据 $id=$_GET ['id' 检查单选按钮];当页面加载时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19265157/

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