我想将单选按钮与 php 文件链接


I want to link a radio button with a php file

当用户

选择下面的单选按钮之一时,我想链接到其中一个php文件,我也放了一个按钮,这个按钮没有出现我不知道为什么:

<html>
<body>
<form action="">
<h4><b>Please choose one of the following options below : </b> </h4>
<input type="radio" name="option" value="search" /> Search <br/>
<input type="radio" name="option" value="open database" /> Open Database<br/>
<input type="radio" name="option" value="administrative page "/> Administrative Page <br/>
</form>
// This button doesn't appear in the web page =( .. dunno why 
<form action="">
<input type="button" value="Choose ">
</form>
</body>
</html>

你应该像这样制作你的代码

<html>
<body>
<form action="">
<h4><b>Please choose one of the following options below : </b> </h4>
<input type="radio" name="option" value="search" /> Search <br/>
<input type="radio" name="option" value="open database" /> Open Database<br/>
<input type="radio" name="option" value="administrative page "/> Administrative Page <br/>
<input type="submit" value="Choose ">
</form>
</body>
</html>

请注意,该按钮与单选选项位于同一<form>标记中,并且它是submit输入类型而不是button

您可以在此处查看结果:http://jsfiddle.net/Sv6q2/

这里有一个没有按钮的例子,但在收音机上带有onclick事件(请注意,你不再需要<form>标签了):

<html>
<body>
<h4><b>Please choose one of the following options below : </b> </h4>
<input type="radio" name="option" value="search" onclick="document.location.href='search.php'"/> Search <br/>
<input type="radio" name="option" value="open database" onclick="document.location.href='database.php'" /> Open Database<br/>
    <input type="radio" name="option" value="administrative page " onclick="document.location.href='admin.php'"/> Administrative Page <br/>
</body>
</html>​

你可以在这里找到结果:http://jsfiddle.net/Sv6q2/2/

你应该

使用 jquery。没有它很难。

首先编写一个小函数来处理点击操作,然后通过以下方式调用你的函数

onChance="myFunction(this);"

还要向单选按钮添加一个自定义属性,其中包含您想要使用的 php 文件名。