Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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
Javascript 如果没有提交按钮,如何检查单选按钮是否已选中?_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript 如果没有提交按钮,如何检查单选按钮是否已选中?

Javascript 如果没有提交按钮,如何检查单选按钮是否已选中?,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,如何检查收音机框的值是Pearson还是euclidean。 所以我现在得到的是: if ($_SERVER['REQUEST_METHOD'] === 'POST') { if($_POST['radio'] == 'Euclidean'){ $get_recommendations = get_recommendations($new_videos,$user_data['username'], $sim_score='sim_euclidean')

如何检查收音机框的值是Pearson还是euclidean。 所以我现在得到的是:

if ($_SERVER['REQUEST_METHOD'] === 'POST')
    {

        if($_POST['radio'] == 'Euclidean'){
        $get_recommendations = get_recommendations($new_videos,$user_data['username'], $sim_score='sim_euclidean');
        }

    }
    // as default i want the pearson method to be used
    else{
        $get_recommendations = get_recommendations($new_videos,$user_data['username'], $sim_score='sim_pearson');
我是否必须有一个按钮来将所选的值分为子项,或者是否有一种方法可以在没有提交按钮的情况下获取该值

这是我的表格:

          <form action="" method="post"> 
          <div class="control-group">
            <h1 style="font-size:22px;">Choose method to recommend with:</h1>
            <label class="control control--radio">Pearson
              <input type="radio" name="radio" value="Pearson" checked="checked"/>
              <div class="control__indicator"></div>
            </label>
            <label class="control control--radio">Euclidean
              <input type="radio" name="radio" value="Euclidean"/>
              <div class="control__indicator"></div>
            </label>
          </div>
          </form>

选择要推荐的方法:
皮尔逊
欧几里得

使用jquery,为radio指定一个radio类或id,例如:

$(document).ready(function()){

$('input:radio[name="radio"]').change(function()){
var value = $('form input[type=radio]:checked').val();  // Gets val of checked on change event

// code to manipulate it, can also be sent to a php file via ajax if you need it that way
}

}
用于将jquery周围的变量传递给php的链接

您需要javascript或jquery@clearshot66JavaScript看起来怎么样,你能帮我解决吗?我会用jquery快速提交答案。给我一个second@clearshot66可以检查该值是否等于php中的某个值吗?或者它还应该包括像u添加的ajax吗?如果它是一个php变量,你必须将它添加到php中,因为JS是前端,php是后端。不,我是指我从jquery检索到的值。如何在php中使用它?是否应该使用ajax?正如我刚才所说,如果您试图将javascriptvalue与php变量进行比较,那么您必须将javascript变量与php进行ajax,以与您想要的php变量进行比较。你到底想干什么?我可能可以帮助您以不同的方式编写它,这样就不需要这样做。我真正想要的是检查该值是否等于Pearson或Euclidean,以便我可以对指定的名称提出建议。在这种情况下,您帮助我使用的代码如何有用?