问题
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:
I'm using jQuery 1.7.1 and TinyMCE 3.5b3 (jQuery package). No other JS libraries.
This code outputs "string", and the anchor tag's href, as expected, when the link is clicked.
$('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:
$('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?
回答1:
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.
I haven't worked yet out why this wasn't a problem with jquery 1.6 and is a problem with 1.7.
Edit:
I was using the jquery plugin like this:
$('.wysiwyg', '#EditForm').tinymce({
-- SETTING HERE
});
and now I have done the following to replicate the behavior I required when using the jquery plugin:
$('.wysiwyg', '#EditForm').each(function(){
id = $(this).attr('id');
var ed = new tinyMCE.Editor(id, {
-- SETTINS HERE --
});
ed.render();
});
Hope this helps
回答2:
jquery 1.7.2 and tinymce 3.5b3 seems to work ok.
回答3:
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.
The advice is just update the editor.
来源:https://stackoverflow.com/questions/9996041/tinymce-and-jquery-attr-is-returning-an-object