如何在 XUl JavaScript 中获取所选复选框值的值
这是我的复选框,它是通过获取 XUL 树的值动态创建的。
var yyahoo = tree.view.getCellText(i, tree.columns.getNamedColumn("yahoo"));
var existing = document.getElementById('box');
var checkbox = document.createElement('checkbox');
capt.appendChild(checkbox);
checkbox.setAttribute('label', yyahoo);
checkbox.setAttribute("checked", "false")
checkbox.setAttribute('style', 'color: green;');
像这样,我在 XUL 文件中动态创建了许多复选框。
当我检查 Mozilla 网站时,它解释说,我必须使用 hasAttribute() 来获取所选复选框的值,这让我感到困惑。
请帮助我获取所选复选框的值。
这是单击即可获取值的按钮。
<row><button label="get" oncommand="get();"/></row>
这是函数:此函数无法正常工作,因为我的函数中缺少某些内容。
function get()
{
// check that the attribute exists before setting a value
var d = document.getElementById("box");
if (d.hasAttribute("checkbox")) {
alert(d);
}
}
感谢您的支持。
This is my check-box and it's created dynamically by getting the value of the XUL tree.
var yyahoo = tree.view.getCellText(i, tree.columns.getNamedColumn("yahoo"));
var existing = document.getElementById('box');
var checkbox = document.createElement('checkbox');
capt.appendChild(checkbox);
checkbox.setAttribute('label', yyahoo);
checkbox.setAttribute("checked", "false")
checkbox.setAttribute('style', 'color: green;');
Like this I have dynamically created many check-boxes in my XUL file.
When I checked Mozilla website, it is explained that, i have to use hasAttribute() to get the value of the selected check-box, which is confusing to me.
Please help me to get the value of the selected check-box.
This is the button to get the values on-click.
<row><button label="get" oncommand="get();"/></row>
This is function: This function is not working 'cause something is missing in my function.
function get()
{
// check that the attribute exists before setting a value
var d = document.getElementById("box");
if (d.hasAttribute("checkbox")) {
alert(d);
}
}
Thanks for your support.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
checkbox
是 ID 为box
的元素的子,而不是属性。尝试这样的操作:checked
属性告诉您当前是否选中该复选框。hasAttribute('checked')
告诉您该属性是否已设置。也许你必须同时使用两者,我不知道。显然,复选框
[MDN] 元素没有属性value
,所以我不知道你在谈论哪个值。The
checkbox
is a child of the element with IDbox
, not an attribute. Try something like this:The
checked
property tells you whether the checkbox is currently selected or not.hasAttribute('checked')
tells you whether the attribute was set or not. Maybe you have to use both, I don't know.Apparently, thecheckbox
[MDN] element has no attributevalue
, so I don't know which value you are talking about.