【发布时间】:2011-05-19 11:46:44
【问题描述】:
我有一个由 AJAX 请求创建的表。每个 TD 内部都有一个文本框输入。这允许用户编辑内容。我想要一个“只读”模式,用户不能编辑内容(由用户自行决定)。为此,我希望用户能够按下一个按钮(单选按钮也可以),用
替换每个文本框输入标记包含文本框的值作为其文本。目前,我的代码将每个输入替换为文本“对象对象”。 (也许我没有正确地将值转换为文本字符串??)任何让我知道出了什么问题的提示都会非常感激。谢谢!!
这是我当前的脚本:
<script type="text/javascript">
$("#permissionsbutton").live('click',function(){
sss = $('.cells').each(function(){$(this).val()});
$(".cells").replaceWith("<p class='readonlycells' type='text'>" + sss + "</p>");
});
// if this worked, I would write another few lines
// to be able to switch back to having inputs
</script>
这是 HTML 的外观:
<div id="readwrite" class="settings">
<h3>Permissions</h3>
<button id="permissionsbutton">Switch to Read Only Mode</button>
</div>
<table><tr>
<td><input class='cells' type=text value='Steve'></td>
<td><input class='cells' type=text value='Mary'></td>
<td><input class='cells' type=text value='Big Bird'></td>
</tr></table>
【问题讨论】:
-
“cells”是 textarea 还是 td 的类?看起来您正在遍历 tds 而不是进入 textareas。
标签: jquery ajax dom dom-manipulation