tinymce插件是否可以做到这一点?我认为访问iframe的其他方法不起作用或不推荐使用。
我有found this 在打印mce插件中尝试了这一点inside the TinyMCE Advanced plugin but it does not work.
var $ = tinymce.dom.DomQuery;
$(\'p\').attr(\'attr\', \'value\').addClass(\'class\');
我已经安装了tinymce高级插件,并尝试将这些行添加到打印插件中。插件被执行,打印对话框打开,但它对dom没有任何影响。WP是否有tinymce的完整版本?
/**
* plugin.js
*
* Released under LGPL License.
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/*global tinymce:true */
var mce_dom = tinymce.dom.DomQuery;
mce_dom(\'p\').attr(\'id\', \'arve\').addClass(\'arve-html-class\');
mce_dom(\'html\').attr(\'id\', \'arve\').addClass(\'arve-html-class\');
tinymce.PluginManager.add(\'print\', function(editor) {
var mce_dom = tinymce.dom.DomQuery;
mce_dom(\'p\').attr(\'id\', \'arve\').addClass(\'arve-html-class\');
mce_dom(\'html\').attr(\'id\', \'arve\').addClass(\'arve-html-class\');
editor.addCommand(\'mcePrint\', function() {
editor.getWin().print();
});
editor.addButton(\'print\', {
title: \'Print\',
cmd: \'mcePrint\'
});
editor.addShortcut(\'Meta+P\', \'\', \'mcePrint\');
editor.addMenuItem(\'print\', {
text: \'Print\',
cmd: \'mcePrint\',
icon: \'print\',
shortcut: \'Meta+P\',
context: \'file\'
});
});
最合适的回答,由SO网友:Abhishek Pandey 整理而成
希望您可以使用fallowing
// Sets class attribute on all paragraphs in the active editor
tinymce.activeEditor.dom.setAttrib(tinymce.activeEditor.dom.select(\'p\'), \'class\', \'myclass\');
// Sets class attribute on a specific element in the current page
tinymce.dom.setAttrib(\'mydiv\', \'class\', \'myclass\');
或者您可以像这样通过jquery添加Id
$(\'div\').find(\'p\').attr(\'id\', \'myid\');