0

我有一些文本区域:

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

我在它们上初始化 jwysiwyg:

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

我还有一个用于保存内容的自定义按钮。现在我怎样才能获得原始的 textarea dom 元素?(我需要在这里区分 jwysiwyg 的几次出现。)

function Wysiwyg() {
  this.controls = {
    save: {
      exec: function () {
        // Magically find the id of the original textarea plx.
        ...

谢谢...

4

1 回答 1

0
$('#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.
        ...

当您为所见即所得运行该函数时,将所选元素发送到该函数并从传入的变量调用该函数中的 jquery...

您必须记住,如果您有多个文本区域,您只能在文档上使用 id 一次,您可以将其用于应用 css,如果您在单击的项目上使用 $(this) 引用,那么您不需要通过其他任何方式调用它:

<textarea class="tArea">Hello</textarea>
<textarea class="tArea">Hello</textarea>
 $('textarea.tArea').wysiwyg($(this));
于 2011-06-19T16:06:58.567 回答