使用jQuery从此html表单中获取textarea的id [英] get the id of a textarea from this html form with jQuery

查看:1191
本文介绍了使用jQuery从此html表单中获取textarea的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

所以这里是 html 输出:



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



 < div class =blogtestid =514> 
< form action =process / updatepost.phpclass =updatepostmethod =post>
< input type =buttonclass = edity value =Edit>
//某些按钮
< br>
< div class =text>
< div class =buildtextid =514> 3< / div>
< div class =editor>
< textarea name =muffinid =516class =ckeditor> 3< / textarea>
< / div>
< / div>
< / form>
< / div>

这里是jQuery im使用:



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

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



另外只是要注意;这工作:

  CKEDITOR.replace('516'); 

但是文本区域是以 foreach 循环,我不能创建一个1000年的编辑替换代码...

解决方案

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

  $(document).on('click','。edity',function(){$ ('。ckeditor')。attr(id); 
CKEDITOR.replace(editorID);
} );


Need help getting and using the id of a textarea so that I can replace it with a ckEDITOR.

So here is the html output:

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.

<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:

$(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. But i get a type b is undefined error in my console log.

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...

解决方案

You are looking for the .checkeditor element from the .edity element. Instead you can do:

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

这篇关于使用jQuery从此html表单中获取textarea的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆