Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取多个输入的单选值并提交到PHP脚本_Php_Ajax_Jquery - Fatal编程技术网

获取多个输入的单选值并提交到PHP脚本

获取多个输入的单选值并提交到PHP脚本,php,ajax,jquery,Php,Ajax,Jquery,今天我想学习如何将多个输入类型的按钮值与原始值进行比较,最后提交到php脚本!如何使用Jquery实现这一点 <html> <body> <div id="leftDiv" class="container"> <form action="" method="get"> <fieldset> <p>Something 0</p> <lable>Yes<

今天我想学习如何将多个输入类型的按钮值与原始值进行比较,最后提交到php脚本!如何使用Jquery实现这一点

<html>
<body>
<div id="leftDiv" class="container"> 
<form action="" method="get"> 
    <fieldset>
        <p>Something 0</p>

        <lable>Yes</label>
        <input type="radio" name="Group0" value="1" >

        <lable>No</label>
        <input type="radio" name="Group0" value="0" >

    </fieldset>

    <fieldset>
        <p>Something 1</p>

        <lable>Yes</label>
        <input type="radio" name="Group1" value="1" >

        <lable>No</label>
        <input type="radio" name="Group1" value="0" >

    </fieldset>

    <fieldset>
        <p>Something 2</p>

        <lable>Yes</label>
        <input type="radio" name="Group2" value="1" >

        <lable>No</label>
        <input type="radio" name="Group2" value="0" >

    </fieldset>

    <fieldset>  
        <input type="submit" name="update" class="button" value="Submit"> 
    </fieldset>
</form>
</div>
</body>
</html>

上面的值是由php脚本生成的,可以是1或100。这是一个非常好的教程,将教您这方面的基本知识:

您可以在JSON中获得单选按钮的值,如下所示:

var radios = {};
$('input[type="radio"]').each(function() {
  radios[$(this).attr('name')] = $(this).attr('value');
});

最简单的方法实际上是设置HTML中所选的正确值,并将.onChange事件绑定到这些值上。否则,使用原始值创建一个隐藏字段,然后按如下方式进行比较

   //a hidden input field with the original value
    <input type='hidden' id='Group0' value='0'/>
    // a set of radio fields that reference the original field we will be comparing with in their 'rel' attribute for easy jQuery selection
    Off<input type='radio' name='Group0' rel='#Group0' class='compareOnChane' value=0/><br/>
    On <input type='radio' name='Group0' rel='#Group0' class='compareOnChane' value=1/>

    <script>
    $(document).ready(function(){
       $('.compareOnChange').live('change',function(){
         if($($(this).attr('rel')).val()!=$(this).val(){
          //the value currently is different than the original value, fire our action
         }

       });

    });

    </script>

你能不能更详细一点,或者至少给我们一个例子?你需要用更多的细节来扩展你的问题,例如,添加你用于单选按钮的HTML,写出一些你想要实现的伪代码,解释你的PHP脚本需要什么输入,等。输入需要不同的名称。输入具有相同的编号,因为Bellong属于同一组。好的,那么radios是存储所有数据的阵列,对吗?假设我将有多个带有单选按钮的div,如果一个div引用了这个特定的div,我该怎么做?那么,在存储了所有的值之后,如何将其发送到php呢?var radios将所有数据存储为JSON。此时,它获取页面上所有单选按钮的数据。要仅对选中的对象执行此操作,需要添加:checked选择器,并且仅对div中的某些对象执行此操作,需要将div ID放在第一位:$'divID input[type=radio]:checked'。要将这些数据发送到php,您需要通读我链接的教程。我在这里重复没有意义。我第一次阅读并在一个小时内完成了那个教程。这真的很好,很值得。它会比很多地方更好地为你总结事情。