Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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 JS获取复选框值添加到URL,然后单击转到URL_Javascript_Jquery - Fatal编程技术网

Javascript JS获取复选框值添加到URL,然后单击转到URL

Javascript JS获取复选框值添加到URL,然后单击转到URL,javascript,jquery,Javascript,Jquery,我有一个脚本如下所示: var baseUrl = 'http://ab3.0e7.myftpupload.com/idmatch_process.php?idmatch_process.php?quizid=". urlencode($quiz_id) ."&escalation=". urlencode($escalation) ."&correctrule=". urlencode($correctrule) ."&page=" . $next_page ."&am

我有一个脚本如下所示:

var baseUrl = 'http://ab3.0e7.myftpupload.com/idmatch_process.php?idmatch_process.php?quizid=". urlencode($quiz_id) ."&escalation=". urlencode($escalation) ."&correctrule=". urlencode($correctrule) ."&page=" . $next_page ."&ans=';

$(document).ready(function () {

// listen to change event (customize selector to your needs)
$('input[type=checkbox]').change(function (e) {

    e.preventDefault();

    if ($(this).is(':checked')) {

        // read in value
        var queryString = $(this).val();

        // loop through siblings (customize selector to your needs)
        var s = $(this).siblings();
        $.each(s, function () {

            // see if checked
            if ($(this).is(':checked')) {

                // append value
                queryString += ' OR ' + $(this).val();
            }
        });

        // jump to url
        window.location = baseUrl + queryString;
    }
});

});

基本上,我获取复选框的值,然后将其附加到baseUrl的and。然后我会自动更改窗口位置。我想做的是让窗口位置的变化不是在复选框点击,而是在一个按钮点击,我将添加。有人有简单的方法吗

您可以创建一个按钮,onclick执行您现在在document ready上执行的操作,该按钮应该可以工作。

您可以创建一个按钮,onclick执行您现在在document ready上执行的操作,该按钮应该可以工作。

如果您将
queryString
的声明移动到外部范围,您可以稍后在单击时使用它

$(document).ready(function () {
  var queryString = '';

  // listen to change event (customize selector to your needs)
  $('input[type=checkbox]').change(function (e) {

    e.preventDefault();

    if ($(this).is(':checked')) {
      // read in value
      queryString = $(this).val();

      // loop through siblings (customize selector to your needs)
      var s = $(this).siblings();
      $.each(s, function () {
        // see if checked
        if ($(this).is(':checked')) {
          // append value
          queryString += ' OR ' + $(this).val();
        }
      });
    }
  });

  $('button.submit').on('click', function() {
    // jump to url
    window.location = baseUrl + queryString;
  });
});
var baseUrl = 'http://ab3.0e7.myftpupload.com/idmatch_process.php?idmatch_process.php?quizid=". urlencode($quiz_id) ."&escalation=". urlencode($escalation) ."&correctrule=". urlencode($correctrule) ."&page=" . $next_page ."&ans=';

var newurl="";

$(document).ready(function () {

// listen to change event (customize selector to your needs)
$('input[type=checkbox]').change(function (e) {

    e.preventDefault();

    if ($(this).is(':checked')) {

        // read in value
        var queryString = $(this).val();

        // loop through siblings (customize selector to your needs)
        var s = $(this).siblings();
        $.each(s, function () {

            // see if checked
            if ($(this).is(':checked')) {

                // append value
                queryString += ' OR ' + $(this).val();
            }
        });

        // jump to url
       newurl = baseUrl + queryString; //setting new url
       $("#yourbutton").show();
    }
});

  $("#yourbutton").click(function(){
     if(newurl!="")
       window.location.href=newurl;
}

});

如果将
queryString
的声明移动到外部作用域,您可以稍后单击使用它

$(document).ready(function () {
  var queryString = '';

  // listen to change event (customize selector to your needs)
  $('input[type=checkbox]').change(function (e) {

    e.preventDefault();

    if ($(this).is(':checked')) {
      // read in value
      queryString = $(this).val();

      // loop through siblings (customize selector to your needs)
      var s = $(this).siblings();
      $.each(s, function () {
        // see if checked
        if ($(this).is(':checked')) {
          // append value
          queryString += ' OR ' + $(this).val();
        }
      });
    }
  });

  $('button.submit').on('click', function() {
    // jump to url
    window.location = baseUrl + queryString;
  });
});
var baseUrl = 'http://ab3.0e7.myftpupload.com/idmatch_process.php?idmatch_process.php?quizid=". urlencode($quiz_id) ."&escalation=". urlencode($escalation) ."&correctrule=". urlencode($correctrule) ."&page=" . $next_page ."&ans=';

var newurl="";

$(document).ready(function () {

// listen to change event (customize selector to your needs)
$('input[type=checkbox]').change(function (e) {

    e.preventDefault();

    if ($(this).is(':checked')) {

        // read in value
        var queryString = $(this).val();

        // loop through siblings (customize selector to your needs)
        var s = $(this).siblings();
        $.each(s, function () {

            // see if checked
            if ($(this).is(':checked')) {

                // append value
                queryString += ' OR ' + $(this).val();
            }
        });

        // jump to url
       newurl = baseUrl + queryString; //setting new url
       $("#yourbutton").show();
    }
});

  $("#yourbutton").click(function(){
     if(newurl!="")
       window.location.href=newurl;
}

});

将ulr存储在全局变量中

仅当url不为空时显示按钮,并在单击时重定向

$(document).ready(function () {
  var queryString = '';

  // listen to change event (customize selector to your needs)
  $('input[type=checkbox]').change(function (e) {

    e.preventDefault();

    if ($(this).is(':checked')) {
      // read in value
      queryString = $(this).val();

      // loop through siblings (customize selector to your needs)
      var s = $(this).siblings();
      $.each(s, function () {
        // see if checked
        if ($(this).is(':checked')) {
          // append value
          queryString += ' OR ' + $(this).val();
        }
      });
    }
  });

  $('button.submit').on('click', function() {
    // jump to url
    window.location = baseUrl + queryString;
  });
});
var baseUrl = 'http://ab3.0e7.myftpupload.com/idmatch_process.php?idmatch_process.php?quizid=". urlencode($quiz_id) ."&escalation=". urlencode($escalation) ."&correctrule=". urlencode($correctrule) ."&page=" . $next_page ."&ans=';

var newurl="";

$(document).ready(function () {

// listen to change event (customize selector to your needs)
$('input[type=checkbox]').change(function (e) {

    e.preventDefault();

    if ($(this).is(':checked')) {

        // read in value
        var queryString = $(this).val();

        // loop through siblings (customize selector to your needs)
        var s = $(this).siblings();
        $.each(s, function () {

            // see if checked
            if ($(this).is(':checked')) {

                // append value
                queryString += ' OR ' + $(this).val();
            }
        });

        // jump to url
       newurl = baseUrl + queryString; //setting new url
       $("#yourbutton").show();
    }
});

  $("#yourbutton").click(function(){
     if(newurl!="")
       window.location.href=newurl;
}

});

将ulr存储在全局变量中

仅当url不为空时显示按钮,并在单击时重定向

$(document).ready(function () {
  var queryString = '';

  // listen to change event (customize selector to your needs)
  $('input[type=checkbox]').change(function (e) {

    e.preventDefault();

    if ($(this).is(':checked')) {
      // read in value
      queryString = $(this).val();

      // loop through siblings (customize selector to your needs)
      var s = $(this).siblings();
      $.each(s, function () {
        // see if checked
        if ($(this).is(':checked')) {
          // append value
          queryString += ' OR ' + $(this).val();
        }
      });
    }
  });

  $('button.submit').on('click', function() {
    // jump to url
    window.location = baseUrl + queryString;
  });
});
var baseUrl = 'http://ab3.0e7.myftpupload.com/idmatch_process.php?idmatch_process.php?quizid=". urlencode($quiz_id) ."&escalation=". urlencode($escalation) ."&correctrule=". urlencode($correctrule) ."&page=" . $next_page ."&ans=';

var newurl="";

$(document).ready(function () {

// listen to change event (customize selector to your needs)
$('input[type=checkbox]').change(function (e) {

    e.preventDefault();

    if ($(this).is(':checked')) {

        // read in value
        var queryString = $(this).val();

        // loop through siblings (customize selector to your needs)
        var s = $(this).siblings();
        $.each(s, function () {

            // see if checked
            if ($(this).is(':checked')) {

                // append value
                queryString += ' OR ' + $(this).val();
            }
        });

        // jump to url
       newurl = baseUrl + queryString; //setting new url
       $("#yourbutton").show();
    }
});

  $("#yourbutton").click(function(){
     if(newurl!="")
       window.location.href=newurl;
}

});