当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery - Can I get the original textarea id from within jwysiwyg?

问题描述:

I have some textareas:

<textarea id="temp1">Hello</textarea>

<textarea id="temp2">Hello</textarea>

...

and I initialize jwysiwyg on them:

$('#temp1').wysiwyg();

$('#temp2').wysiwyg();

I also have a custom button for saving the content. Now how can I get a hold of the original textarea dom element? (I need to distinguish between several occurances of jwysiwyg here.)

function Wysiwyg() {

this.controls = {

save: {

exec: function () {

// Magically find the id of the original textarea plx.

...

Thanks...

网友答案:
$('#temp').wysiwyg($(this));

function Wysiwyg(textarea) {
  this.controls = {
    save: {
      exec: function () {
        $(textarea).val(); //return selected text area value
        // Magically find the id of the original textarea plx.
        ...

When you run the function for wysiwyg, send the selected element through to the function and call the jquery within that function from the passed in variable...

You must remember you can only use id once on the document if you have multiple text areas you can put this for applying css, if you use the $(this) reference on a clicked item then you do not need to call it by anything else:

<textarea class="tArea">Hello</textarea>
<textarea class="tArea">Hello</textarea>
 $('textarea.tArea').wysiwyg($(this));
分享给朋友:
您可能感兴趣的文章:
随机阅读: