【发布时间】:2011-09-18 20:21:47
【问题描述】:
我的 HTML 代码是
<table>
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td></tr>
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td></tr>
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td></tr>
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td></tr>
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td></tr>
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td></tr>
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td></tr>
<tr><td><input type="checkbox"></td><td><input type="checkbox"></td></tr>
</table>
我的 JQuery 代码是(不是我写的,一些 Stackoverflow 的使用帮助了我,我感谢他)
$('TABLE TBODY TR').each(function()
{
var lastd = $(this).children('tr td:last').find('input:checkbox');
var parentlast = lastd.parent();
lastd.remove();
parentlast.append("<input type='radio'>"); // want to add the same properties of the removed checkbox
});
请有人帮助我。
【问题讨论】:
-
并不是说它真的很重要,但为什么要这样做呢?基于人们的期望,你会把他们搞糊涂。 (例如,如果我看到一个复选框,我希望能够选择多个项目。如果我看到一个单选按钮,我希望只能选择一个。)您更改约定的任何原因?我只是好奇。
-
有什么理由不能只渲染
radio类型的输入吗? -
我的服务器在表格中生成所有复选框,这是我们的要求,但在某些情况下,我们使用最后一个复选框作为独占。这就是我想要这样做的原因:-)
-
@JasCav:虽然我通常建议不要更改常规约定,但 OP 所要求的内容可能不会让普通用户感到困惑,具体取决于他的应用程序。
标签: jquery jquery-ui radio-button dom-manipulation html