我已经做了好几天了,我用谷歌搜索了一遍,但似乎找不到确切的内容。我有一个菜单选项卡,它由如下的php脚本填充:
<?php include 'db_connector.php';
$result = mysqli_query($con,"SELECT * FROM os_scope");
while($row = mysqli_fetch_array($result)) {
echo "<button type='radio'>"."<li>"."<div class='title'>"."<a href='#myPanel' >".$row['name']."</a>"."</div>"."</li>"."</button>";
}
?>
结果的输出是:
Billing
Custom
Customer
Product
当我选择其中任何一个,即计费时,它会打开#mypanel
我希望每次我选择一个项目,即Billing,值"Billing"都应该发布到面板上,然后我可以在那里使用这个值来查询MySQL数据库。其余项目也是如此。
如有任何建议,我们将不胜感激。提前谢谢。
没有<button type='radio'>
这样的东西
使用<input type='radio' value='value'>
试试这个:
echo "<li><input type='radio' value='".$row['name']."' /><div class='title'><a href='#myPanel' >".$row['name']."</a></div></li>";
此外,没有理由到处都这样做:"."
只让字符串是一个字符串。这就是弦乐最擅长的地方。
这正是我想要的,
<!DOCTYPE html>
<html>
<body>
<?php include 'db_connector.php';
$result = mysqli_query($con,"SELECT * FROM os_scope");
while($row = mysqli_fetch_array($result)) {
$row['name'];
echo "<input type='radio' name='os' value=".$row['name']." id='myRadio'>";
}
?>
<p>Click the "Try it" button to display the value of the radio button.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementsByName('os');
var rate_value;
for(var i = 0; i < x.length; i++){
if(x[i].checked){
rate_value = x[i].value;
break;
}
}
document.getElementById("demo").innerHTML = rate_value;
}
</script>
</body>
</html>