php 中 let一个网页,做ture 和false的选择
时间: 2024-12-15 16:23:30 浏览: 45
在PHP中,你可以创建一个简单的HTML页面,通过JavaScript来呈现true和false的选择。下面是一个基本的示例:
```php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>True or False Choice</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <!-- 如果需要,可以引入jQuery -->
</head>
<body>
<h1>Choose between True or False:</h1>
<input type="radio" id="true" name="choice" value="true"> True<br>
<input type="radio" id="false" name="choice" value="false"> False<br>
<button onclick="makeDecision()">Submit</button>
<p id="result"></p>
<script>
function makeDecision() {
var choice = $("input[name='choice']:checked").val(); // 获取选中的值
if (choice === "true") {
document.getElementById("result").innerHTML = "You chose True!";
} else if (choice === "false") {
document.getElementById("result").innerHTML = "You chose False!";
}
}
</script>
</body>
</html>
```
在这个例子中,用户可以选择"True"或"False",点击提交按钮后,JavaScript会获取所选值并显示相应的消息。如果不需要外部库,可以直接在HTML里使用`<script>`标签编写JavaScript函数。
阅读全文
相关推荐

















