Javascript 变差下拉列表为单选按钮
我正在尝试使用jquery动态地将下拉列表转换为单选按钮,下面是代码Javascript 变差下拉列表为单选按钮,javascript,jquery,html,Javascript,Jquery,Html,我正在尝试使用jquery动态地将下拉列表转换为单选按钮,下面是代码 jQuery(document).ready(function($) { $('select#pa_size option[value=' + $choice + ']').attr('selected', true).parent().trigger('change'); }); 这个密码给我单选按钮。但它不适用于期权。 请单击添加到购物车链接以查看直接页面。jQuery(文档)。就绪(函数($){ jQuery(
jQuery(document).ready(function($) {
$('select#pa_size option[value=' + $choice + ']').attr('selected', true).parent().trigger('change');
});
这个密码给我单选按钮。但它不适用于期权。
请单击添加到购物车链接以查看直接页面。jQuery(文档)。就绪(函数($){
jQuery(document).ready(function($){
//Get Exising Select Options
$('select#pa_size').each(function(i, select){
var $select = $(select);
$select.find('option').each(function(j, option){
var $option = $(option);
// Create a radio:
var $radio = $('<input type="radio" />');
// Set name and value:
$radio.attr('name', $select.attr('name')).attr('value', $option.val());
// Set checked if the option was selected
if ($option.attr('selected')) $radio.attr('checked', 'checked');
// Insert radio before select box:
$select.before($radio);
// Insert a label:
$select.before(
$("<label />").attr('for', $select.attr('name')).text($option.text())
);
// Insert a <br />:
$select.before("<br/>");
});
$select.remove();
});
$('.single_variation_wrap').css('display','block');
//获取退出选择选项
$('select#pa_size')。每个(函数(i,select){
变量$select=$(select);
$select.find('option')。每个(函数(j,option){
var$选项=$(选项);
//创建一个收音机:
变量$radio=$('');
//设置名称和值:
$radio.attr('name',$select.attr('name')).attr('value',$option.val());
//如果选择了该选项,则设置为选中状态
if($option.attr('selected'))$radio.attr('checked','checked');
//在选择框之前插入收音机:
$select.before($radio);
//插入标签:
$select.before(
$(“”).attr('for',$select.attr('name')).text($option.text())
);
//插入一个
:
$select.before(“
”);
});
$select.remove();
});
$('.single_variation_wrap').css('display','block');
}))//这是最新的代码。同样的问题你能分享代码吗,这样我们就可以处理它了?