如何在PHP中使用AJAX检查单选按钮值?

如何在PHP中使用AJAX检查单选按钮值?,php,ajax,radio-button,Php,Ajax,Radio Button,我将使用PHP中的AJAX获取选中的单选按钮值。我已经完成了以下代码,但无法继续 我需要你的帮助 ajax\u radio.php <html> <head> <script type="text/javascript" src="ajax.js" ></script> </head> <body> <input type="radio" name="radio1">Blue</

我将使用PHP中的AJAX获取选中的单选按钮值。我已经完成了以下代码,但无法继续

我需要你的帮助

ajax\u radio.php

<html>
  <head>
    <script type="text/javascript" src="ajax.js" ></script>
  </head>
  <body>
    <input type="radio" name="radio1">Blue</input>
    <input type="radio" name="radio2">White</input>
    <input type="radio" name="radio3">Red</input>
    <input type="button" name="btn" value="Click" onClick="hello('a')"></input><br />
   <input type="text" id="btn_get" name="get_btn_value"></input>
  </body>
</html>
你知道如何完成这个吗?提前感谢。:)

编辑:

我现在不能在这里发布代码,因为网络速度太慢了。对不起

我已经把它分享了。你能先下载它,然后帮我吗?非常感谢


我回家后必须更新它。太糟糕了

因为我主要使用Jquery,所以我在这里编写了一个Jquery,用于检查单选按钮值,因为它更简单、更干净:

<script src="http://www.google.com/jsapi"></script>
<script>
    google.load("jquery", "1.4.0");
</script>
<script type="text/javascript">
    $(function() {
        $('#buttoncheck').click(function () {
            var var_name = $("input[name='radio1']:checked").val();
            $('#btn_get').val(var_name);
        });
    });
</script>
<html>
    <head>
        <script type="text/javascript" src="ajax.js" ></script>
    </head>
    <body>
        <input type="radio" value="Blue" name="radio1">Blue</input>
        <input type="radio" value="White" name="radio1">White</input>
        <input type="radio" value="Red" name="radio1">Red</input>
        <input id="buttoncheck" type="button" name="btn" value="Click"></input>
        <br />
        <input type="text" id="btn_get" name="get_btn_value"></input>
    </body>
</html>
最后。这会将变量的值放入具有#btn_get as id:

$('#btn_get').val(var_name);

你不能粘贴代码,因为我们的网络很慢?我以为粘贴是windows的标准功能。我可以粘贴代码,但当我提交页面时,结果却是空白的。我试着在其他地方发帖或者制作一个zip文件。对此我很抱歉。只需将ajax的源代码用Select your code包装,然后在编辑器中单击这个带有1和0的漂亮小按钮,即可粘贴它。代码总是有四个空格。如果有人真的下载了它,帮我们大家一个忙,把它粘贴进去。@非常感谢RJD22,你太棒了!!!你救了我,给了我一个很好的指导。虽然已经做完了,但我还是得跳进去。我现在正在学习使用jQuery,但我仍然很难理解您的代码。我仍然想尝试用纯ajax实现它。@garcon1986:jQuery是使用“纯”ajax的“纯”JS。唯一能让你的生活更轻松的是,你不必担心跨浏览器兼容性和其他一些好帮手。@Felix,谢谢你的解释。jQuery对于开发人员来说是一个非常好的工具。干杯。@garcon1986:我写的剪报很简单。因为你想学习如何使用它,我添加了一个小explanation@Danny是的,实际上非常容易,只要将其更改为
$(“input[name='radio1'])
var var_name = $("input[name='radio1']:checked").val(); 
$('#btn_get').val(var_name);