Javascript-如何创建复选框? [英] Javascript-How to create a checkbox?

查看:115
本文介绍了Javascript-如何创建复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function checkData(PrjList)
{

   var handler = document.getElementById("LoadCheckbox");
   var val=PrjList;
   console.log(val);
 var checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.name = "name";
checkbox.value = val;
checkbox.id = val;

var label = document.createElement('label')
label.appendChild(document.createTextNode(val));

handler.appendChild(checkbox);
handler.appendChild(label);
}





上面是一个创建复选框的函数.'Prjlist'是复选框中给出的值,从其他function.i传递,可以显示值,但复选框符号不会出现。

任何人都可以确定这里有什么问题???请帮助...



Above is a function to create a checkbox.'Prjlist' is the values to be given in the checkbox,that is passed from other function.i can display the values but the checkbox sign doesnot appear.
Can anybody identify what is the problem here???Please help...

推荐答案





Hi,

label.appendChild(checkbox);   // add the box to the element
label.appendChild(document.createTextNode(val));// add the description to the element

// add the label element to your div
document.getElementById('div').appendChild(label);





使用它并检查结果一次。



祝你好运



use this and check the result once.

Good Luck


参考





http:// stackoverflow。 com / questions / 866239 / creating-the-checkbox-dynamic-using-javascript [ ^ ]


我发布的代码是正确的,因为其中应用了css样式,复选框不可见..谢谢帮助every1
The code I posted was correct,because of the css style applied in it the checkbox was not visible..Thanks for the help every1


这篇关于Javascript-如何创建复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆