如何使用Javascript将带有复选框的列表更改为下拉列表?
我使用的是第三方软件,没有权限编辑页面上的代码,但我可以添加Javascript来修改内容。我正在寻找一个解决方案,可以帮助改变这个复选框项目列表下拉列表。我以前很少使用Javascript。提前谢谢 扣除时限: PD Til进一步通知 海鹰三年承诺 ... 等如何使用Javascript将带有复选框的列表更改为下拉列表?,javascript,checkbox,radial,Javascript,Checkbox,Radial,我使用的是第三方软件,没有权限编辑页面上的代码,但我可以添加Javascript来修改内容。我正在寻找一个解决方案,可以帮助改变这个复选框项目列表下拉列表。我以前很少使用Javascript。提前谢谢 扣除时限: PD Til进一步通知 海鹰三年承诺 ... 等 我不会为您编写完整的js函数,但我会指出一些有用的想法: 您可以参考答案来获取td元素的值。然后,您可以使用这些值来构建相关选项的数组 t = document.getElementById("table"), // This hav
我不会为您编写完整的js函数,但我会指出一些有用的想法: 您可以参考答案来获取td元素的值。然后,您可以使用这些值来构建相关选项的数组
t = document.getElementById("table"), // This have to be the ID of your table, not the tag
d = t.getElementsByTagName("tr")[0],
r = d.getElementsByTagName("td")[0];
使用for循环(如answer)从数组中构建select下拉列表
将html附加到DOM并删除复选框列表,或者使用该方法
我不会为您编写完整的js函数,但我会指出一些有用的想法: 您可以参考答案来获取td元素的值。然后,您可以使用这些值来构建相关选项的数组
t = document.getElementById("table"), // This have to be the ID of your table, not the tag
d = t.getElementsByTagName("tr")[0],
r = d.getElementsByTagName("td")[0];
使用for循环(如answer)从数组中构建select下拉列表
将html附加到DOM并删除复选框列表,或者使用该方法
首先需要添加一个select元素
$.each(inpts, function(ii,val){
var optId = $(val).attr('id'), //pull out the id
optVal = $(val).attr('value'), //pull out the value
optData = $(val).attr('name'); // pull out the name. will be used as a data attribute.
//append to the select element.
$('#mySelc').append('<option id="'+optId+'" data="'+optData+'" value="'+optVal+'">'+optVal+'</option>');
});
我不确定你需要什么样的容器元素,所以我选择了主体。您可以根据需要进行更改
$('body').append('<select id="mySelc"></select>');
然后循环遍历它们,取出所需内容并将其附加到select元素
$.each(inpts, function(ii,val){
var optId = $(val).attr('id'), //pull out the id
optVal = $(val).attr('value'), //pull out the value
optData = $(val).attr('name'); // pull out the name. will be used as a data attribute.
//append to the select element.
$('#mySelc').append('<option id="'+optId+'" data="'+optData+'" value="'+optVal+'">'+optVal+'</option>');
});
我假设您使用的是jQuery,但如果需要,我可以用纯JavaScript重写它。您需要做的第一件事是添加一个select元素
$.each(inpts, function(ii,val){
var optId = $(val).attr('id'), //pull out the id
optVal = $(val).attr('value'), //pull out the value
optData = $(val).attr('name'); // pull out the name. will be used as a data attribute.
//append to the select element.
$('#mySelc').append('<option id="'+optId+'" data="'+optData+'" value="'+optVal+'">'+optVal+'</option>');
});
我不确定你需要什么样的容器元素,所以我选择了主体。您可以根据需要进行更改
$('body').append('<select id="mySelc"></select>');
然后循环遍历它们,取出所需内容并将其附加到select元素
$.each(inpts, function(ii,val){
var optId = $(val).attr('id'), //pull out the id
optVal = $(val).attr('value'), //pull out the value
optData = $(val).attr('name'); // pull out the name. will be used as a data attribute.
//append to the select element.
$('#mySelc').append('<option id="'+optId+'" data="'+optData+'" value="'+optVal+'">'+optVal+'</option>');
});
我假设您正在使用jQuery,但如果需要,我可以用纯JavaScript重写它。您可以使用jQuery吗?您可以使用jQuery吗?