TinyMCE和jQuery - attr()返回一个Object

时间:2021-08-18 20:34:34

I've solved this by using data() instead of attr(), but I'd still like to know if this is just me, and what's causing it:

我已经通过使用data()而不是attr()解决了这个问题,但我仍然想知道这是否只是我,以及是什么导致它:

I'm using jQuery 1.7.1 and TinyMCE 3.5b3 (jQuery package). No other JS libraries.

我正在使用jQuery 1.7.1和TinyMCE 3.5b3(jQuery包)。没有其他JS库。

This code outputs "string", and the anchor tag's href, as expected, when the link is clicked.

当单击链接时,此代码按预期输出“string”和锚标记的href。

$('a.page_item_delete').on('click', function(event){
    event.preventDefault();
    var $this = $(this);
    console.log(typeof $this.attr('href'));
    console.log($this.attr('href'));
});

When I activate TinyMCE on some textareas on the page, it outputs "Object" and, of course, attr() stops returning an expected value. I'm activating TinyMCE via:

当我在页面上的某些textareas上激活TinyMCE时,它会输出“Object”,当然,attr()会停止返回预期值。我通过以下方式激活TinyMCE:

$('textarea.tinymce').tinymce(options);

Has anyone else experienced this behaviour with TinyMCE? Is there a known bug, or workaround? Why is TinyMCE apparently affecting unrelated HTML elements on the page?

有没有其他人用TinyMCE经历过这种行为?是否存在已知错误或解决方法?为什么TinyMCE显然会影响页面上不相关的HTML元素?

3 个解决方案

#1


9  

I am having the same problem. It is being caused by the tinymce-jquery package overriding the attr and css methods of the jquery object. It seems (sadly) that the solution is to not use the jquery version of tinymce.

我有同样的问题。它是由tinymce-jquery包引起的,它覆盖了jquery对象的attr和css方法。 (遗憾的是)解决方案似乎是不使用jitery版本的tinymce。

I haven't worked yet out why this wasn't a problem with jquery 1.6 and is a problem with 1.7.

我还没有解决为什么这不是jquery 1.6的问题,而且是1.7的问题。

Edit:

I was using the jquery plugin like this:

我正在使用这样的jquery插件:

$('.wysiwyg', '#EditForm').tinymce({
    -- SETTING HERE
});

and now I have done the following to replicate the behavior I required when using the jquery plugin:

现在我已经完成以下操作来复制使用jquery插件时所需的行为:

$('.wysiwyg', '#EditForm').each(function(){
    id = $(this).attr('id');
    var ed = new tinyMCE.Editor(id, {
    -- SETTINS HERE --          
    });
    ed.render();
});

Hope this helps

希望这可以帮助

#2


1  

jquery 1.7.2 and tinymce 3.5b3 seems to work ok.

jquery 1.7.2和tinymce 3.5b3似乎工作正常。

#3


0  

When I had the same problem I updated TinyMCE editor (jQuery package) to 3.5.11 version and the behavior of attr() method became normal. The main problem was to know that it's a conflict between TinyMCE and jQuery attr() method. I didn't understand this one at once.

当我遇到同样的问题时,我将TinyMCE编辑器(jQuery包)更新为3.5.11版本,并且attr()方法的行为变得正常。主要问题是要知道这是TinyMCE和jQuery attr()方法之间的冲突。我立刻不理解这个。

The advice is just update the editor.

建议只是更新编辑器。

#1


9  

I am having the same problem. It is being caused by the tinymce-jquery package overriding the attr and css methods of the jquery object. It seems (sadly) that the solution is to not use the jquery version of tinymce.

我有同样的问题。它是由tinymce-jquery包引起的,它覆盖了jquery对象的attr和css方法。 (遗憾的是)解决方案似乎是不使用jitery版本的tinymce。

I haven't worked yet out why this wasn't a problem with jquery 1.6 and is a problem with 1.7.

我还没有解决为什么这不是jquery 1.6的问题,而且是1.7的问题。

Edit:

I was using the jquery plugin like this:

我正在使用这样的jquery插件:

$('.wysiwyg', '#EditForm').tinymce({
    -- SETTING HERE
});

and now I have done the following to replicate the behavior I required when using the jquery plugin:

现在我已经完成以下操作来复制使用jquery插件时所需的行为:

$('.wysiwyg', '#EditForm').each(function(){
    id = $(this).attr('id');
    var ed = new tinyMCE.Editor(id, {
    -- SETTINS HERE --          
    });
    ed.render();
});

Hope this helps

希望这可以帮助

#2


1  

jquery 1.7.2 and tinymce 3.5b3 seems to work ok.

jquery 1.7.2和tinymce 3.5b3似乎工作正常。

#3


0  

When I had the same problem I updated TinyMCE editor (jQuery package) to 3.5.11 version and the behavior of attr() method became normal. The main problem was to know that it's a conflict between TinyMCE and jQuery attr() method. I didn't understand this one at once.

当我遇到同样的问题时,我将TinyMCE编辑器(jQuery包)更新为3.5.11版本,并且attr()方法的行为变得正常。主要问题是要知道这是TinyMCE和jQuery attr()方法之间的冲突。我立刻不理解这个。

The advice is just update the editor.

建议只是更新编辑器。