html 重定向取决于选中的单选按钮选项
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 重定向取决于选中的单选按钮选项相关的知识,希望对你有一定的参考价值。
<!-- START code for redirect depending on selected radio button option -->
<script>
$(document).ready(function() {
//define radio button label
var radioButtonLabel = 'Workshop Date/Time';
//define array with redirect URLs for each option
var redirectUrlsArray = ['https://facebook.com', 'https://google.com'];
//DO NOT EDIT BELOW THIS LINE
//define radio button element
var $radio = $('input[name="' + window.btoa(radioButtonLabel) + '"]');
//define array with options
var optionsArray = [];
$radio.each(function(i, e) {
optionsArray[i] = $(e).val();
});
//define change event
$radio.change(function() {
//go through the array
for (var i = 0; i < optionsArray.length; i++) {
//find the selected option
if ($(this).val() === optionsArray[i]) {
//switch the redirect URL with the one corresponding to that option
$(this).closest('form').find('input[name="redirect"]').val(redirectUrlsArray[i]);
}
}
});
});
</script>
<!-- END code for redirect depending on selected radio button option -->
<!-- START code for redirect depending on selected radio button option -->
<script>
$(document).ready(function() {
//define radio button label
var radioButtonLabel = 'Radio';
//define array with options
var optionsArray = ['Opt1', 'Opt2'];
//define array with redirect URLs for each option
var redirectUrlsArray = ['https://instapage.com', 'https://google.com'];
//define change event
$('input[name="' + window.btoa(radioButtonLabel) + '"]').change(function() {
//go through the array
for (var i = 0; i < optionsArray.length; i++) {
//find the selected option
if ($(this).val() == optionsArray[i]) {
//switch the redirect URL with the one corresponding to that option
$(this).closest('form').find('input[name="redirect"]').val(redirectUrlsArray[i]);
}
}
});
});
</script>
<!-- END code for redirect depending on selected radio button option -->
以上是关于html 重定向取决于选中的单选按钮选项的主要内容,如果未能解决你的问题,请参考以下文章