简体   繁体   English

使用jQuery从此html表单获取textarea的ID

[英]get the id of a textarea from this html form with jQuery

Need help getting and using the id of a textarea so that I can replace it with a ckEDITOR. 需要帮助来获取和使用textarea的id ,以便我可以将其替换为ckEDITOR。

So here is the html output: 因此,这是html输出:

NOTE: This is the output of a foreach loop, for every database result, this is the html output and the textarea ID is a number generated from the id of the row. 注意:这是一个输出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>

And here is the jQuery im using: 这是使用jQuery的即时消息:

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

This doesnt work, I'm not the most advanced with jQuery so not sure why. 这行不通,我不是jQuery最先进的人,所以不确定为什么。 But i get a type b is undefined error in my console log. 但是我的控制台日志中出现类型b是未定义的错误。

Also just to note; 也只是要注意; this works: 这有效:

CKEDITOR.replace('516');

but the text areas are loaded dynamically in a foreach loop and I can't be creating a replace code for 1000's of editors... 但是文本区域是在foreach循环中动态加载的,因此我无法为1000个编辑器创建替换代码...

You are looking for the .checkeditor element from the .edity element. 您正在寻找.checkeditor从元素.edity元素。 Instead you can do: 相反,您可以执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM