性别
<input type='radio' name='gender' value='male'>Male
<input type='radio' name='gender' value='female'>Female
<input type='radio' name='gender' value='kid'>Kid
品牌
<input type='radio' name='brand' value='brand1'>Brand1
<input type='radio' name='brand' value='brand2'>Brand2
<input type='radio' name='brand' value='brand3'>Brand3
<script>
$(document).ready(function() {
$('.chkbox').on('change', function() {
if ($(this).is(':checked')) {
var url = 'url.php?' + $(this).val();
console.log(url);
window.location = url;
}
});
});
</script>
我希望网址像url.php?brand = $ brand&amp;&amp; gender = $ gender 请帮忙
答案 0 :(得分:1)
你去。
$(document).ready(function() {
$('input[type="radio"]').on('change', function() {
var url = 'url.php?';
$('input[type="radio"]').each(function(index, obj) {
if (obj.checked)
url += obj.name + '=' + obj.value + '&';
});
url = url.slice(0, url.lastIndexOf('&'));
console.log(url);
//window.location = url;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input type='radio' name='gender' value='male'>Male
<input type='radio' name='gender' value='female'>Female
<input type='radio' name='gender' value='kid'>Kid
<input type='radio' name='brand' value='brand1'>Brand1
<input type='radio' name='brand' value='brand2'>Brand2
<input type='radio' name='brand' value='brand3'>Brand3