【问题标题】:get the id of a textarea from this html form with jQuery使用 jQuery 从此 html 表单获取 textarea 的 id
【发布时间】:2014-02-25 12:23:28
【问题描述】:

需要帮助获取和使用 textarea 的 id,以便我可以用 ckEDITOR 替换它。

所以这里是html 输出:

注意:这是foreach 循环的输出,对于每个数据库结果,这是html 输出,textarea ID 是从行的id 生成的数字。

<div class="blogtest" id="514">
<form action="process/updatepost.php" class="updatepost" method="post">
<input type="button" class=edity value="Edit">
// SOME BUTTONS
<br>
<div class="text">
<div class="buildtext" id="514">3</div>
<div class="editor">
<textarea name="muffin" id="516" class="ckeditor">3</textarea>
</div>
</div>
</form>
</div>

这是使用的 jQuery 即时消息:

$(document).on('click','.edity',function(){
var editorID = $(this).find('.ckeditor').attr("id")
CKEDITOR.replace(editorID);
});

这不起作用,我不是最先进的 jQuery,所以不知道为什么。但是我在控制台日志中得到一个类型 b 是未定义的错误。

还要注意;这行得通:

CKEDITOR.replace('516');

但文本区域是在 foreach 循环中动态加载的,我无法为 1000 个编辑器创建替换代码...

【问题讨论】:

  • 所有文本区域都使用相同的 ID 吗? ID 必须是唯一的。

标签: javascript php jquery html attr


【解决方案1】:

您正在从.edity 元素中寻找.checkeditor 元素。相反,您可以这样做:

$(document).on('click','.edity',function() {
    var editorID = $(this).parents('.blogtest').find('.ckeditor').attr("id");
    CKEDITOR.replace(editorID);
});

【讨论】:

  • 英雄。新它很简单。现在我知道了未来的父部分。我会尽可能将其标记为正确:) 谢谢!
  • 我可以找到所有兄弟姐妹的 id 吗?
猜你喜欢
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 2012-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-12
  • 2012-10-02
相关资源
最近更新 更多