Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.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 如何为两种不同类型的输入组合.change(function(),并将值发送到同一个函数参数_Javascript_Jquery - Fatal编程技术网

Javascript 如何为两种不同类型的输入组合.change(function(),并将值发送到同一个函数参数

Javascript 如何为两种不同类型的输入组合.change(function(),并将值发送到同一个函数参数,javascript,jquery,Javascript,Jquery,选中复选框后,我将值发送到名为sendtobox()的函数。该函数通过ajax调用从数据库获取数据 现在我想让html的范围滑块也将其值发送到此函数 请问我该怎么做 <script> $(".slider").change(function() { var value = $(this).val(); sendtobox(value); }); $("input[type=checkbox]").change(funct

选中复选框后,我将值发送到名为
sendtobox()
的函数。该函数通过ajax调用从数据库获取数据

现在我想让html的范围滑块也将其值发送到此函数

请问我该怎么做

<script>
       $(".slider").change(function() {
       var value = $(this).val();
       sendtobox(value);
      });

    $("input[type=checkbox]").change(function() {  
     var selectedval = $(this).val();
     if($(this).is(":checked")) {
        var selectedtext = $(this).next().text();
        sendtobox(selectedval);
     }
      else {
        $("th."+selectedval).remove();//controls removing from boxA
     }
    });



</script>
已编辑 现在我知道我可以通过字符串url传递,比如
this:xmlhttp.open(“GET”,“getsubjects.php?q=“+param+”&r=“+param2,true”);


但是脚本没有正确地传递值,因为我用数字10替换了
param2
值,它可以工作。

在下面的代码中,在进行ajax调用时,在从输入复选框更改调用时发送滑块值,反之亦然。请检查这是否有助于您的解决方案

<script>
       $(".slider").change(function() {
       var value = $('.slider').slider("option", "value");
       sendtobox(value, $("input[type=checkbox]").val());
      });

    $("input[type=checkbox]").change(function() {  
     var selectedval = $(this).val();
     if($(this).is(":checked")) {
        var selectedtext = $(this).next().text();
        sendtobox(selectedval, $('.slider').slider("option", "value"));
     }
      else {
        $("th."+selectedval).remove();//controls removing from boxA
     }
    });
</script>

$(“.slider”).change(函数(){
变量值=$('.slider')。slider(“选项”,“值”);
sendtobox(值,$(“输入[type=checkbox]”).val();
});
$(“输入[type=checkbox]”)。更改(函数(){
var selectedval=$(this.val();
如果($(this).is(“:checked”)){
var selectedtext=$(this.next().text();
sendtobox(selectedval,$('.slider').slider(“选项”,“值”));
}
否则{
$(“th.+selectedval).remove();//控件从boxA中删除
}
});

注意,出现两个变量
selectedval
selectedtext
;不确定传递给
sendtobox
的值是否应根据选中的
复选框进行切换

试一试

函数sendtobox(param,param2){
//使用'param','param2'进行操作`
console.log(param,param2);
/*
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
if(this.responseText!==null){
var ajaxElm=document.getElementById('boxA');
ajaxElm.innerHTML=this.responseText+ajaxElm.innerHTML;
//加在前面
}
}
}
open(“GET”、“getsubjects.php?q=“+param+”r=“+param2,true”);
xmlhttp.send();
*/
}
var值=null
,selectedtext=null
,selectedval=null;
$(“输入[type=checkbox],.slider”).change(函数(){
if($(this).is(“.slider”)){
value=this.value;
};
if($(this).is(“[type=checkbox]”){
selectedval=this.value;
如果($(this).is(“:checked”)){
selectedtext=$(this.next().text();
}
};
sendtobox(值,selectedval);
});

abc

$(“#滑块1”).change(函数(){
var值=$(this.val();
sendtobox(值,$(“输入[type=checkbox]”).val();
});
$(“输入[type=checkbox]”)。更改(函数(){
var selectedval=$(this.val();
如果($(this).is(“:checked”)){
var selectedtext=$(this.next().text();
sendtobox(selectedval,$(“#slider1”).val();
}
否则{
$(“th.+selectedval).remove();//控件从boxA中删除
}
});
open(“GET”、“getsubjects.php?q=“+param+”&r=“+param2,true”);

我不确定sit是否没有像预期的那样在文本框中传递滑块值。我实际上是在将值传递给函数,因为该函数从数据库中获取php页面中那些复选框值的数据。在该php页面中,文本框将显示在html上。因此我想在文本框值中显示滑块值。您是说t吗您不能按预期获得滑块的值吗?您能详细说明一下您想说什么吗?简单来说,在getsubjects.php页面中,我必须以以下形式获得滑块的值$slider=$\u get['slider']…如何做,我想我可以通过函数传递它,但它似乎没有传递任何东西。如果我提交表单,我可以得到slider的值。但是在提交之前,我想得到该值并将其显示在文本框中…我只想知道如何通过sendtobox()函数将该值传递到上面提到的php页面
<script>
       $(".slider").change(function() {
       var value = $('.slider').slider("option", "value");
       sendtobox(value, $("input[type=checkbox]").val());
      });

    $("input[type=checkbox]").change(function() {  
     var selectedval = $(this).val();
     if($(this).is(":checked")) {
        var selectedtext = $(this).next().text();
        sendtobox(selectedval, $('.slider').slider("option", "value"));
     }
      else {
        $("th."+selectedval).remove();//controls removing from boxA
     }
    });
</script>
<script>
       $("#slider1").change(function() {
       var value = $(this).val();
       sendtobox(value, $("input[type=checkbox]").val());
      });

    $("input[type=checkbox]").change(function() {  
     var selectedval = $(this).val();
     if($(this).is(":checked")) {
        var selectedtext = $(this).next().text();
        sendtobox(selectedval, $("#slider1").val());
     }
      else {
        $("th."+selectedval).remove();//controls removing from boxA
     }
    });
</script>




xmlhttp.open("GET","getsubjects.php?q="+param+"&r="+param2,true);