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;
}
});