Javascript 如何在TinyMCE中对齐图像?
我正在编写一个脚本,将在TinyMCE文本区域的光标处插入一个图像。我希望能够将“对齐”属性添加到此图像。在添加align属性之前,一切都会顺利进行。无论我在模式中选择什么选项,我插入的图像总是左对齐Javascript 如何在TinyMCE中对齐图像?,javascript,jquery,tinymce,Javascript,Jquery,Tinymce,我正在编写一个脚本,将在TinyMCE文本区域的光标处插入一个图像。我希望能够将“对齐”属性添加到此图像。在添加align属性之前,一切都会顺利进行。无论我在模式中选择什么选项,我插入的图像总是左对齐 var ed = tinyMCE.get('article-content'); // get editor instance var range = ed.selection.getRng();
var ed = tinyMCE.get('article-content'); // get editor instance
var range = ed.selection.getRng(); // get range
var newNode = ed.getDoc().createElement ( "img" ); // create img node
newNode.src=attachment.prop('src');
newNode.width = attachment.width();
newNode.height = attachment.height();
newNode.align = $('input[name="align"]').val(); // add src attribute
range.insertNode(newNode);
/* Clear previous values */
$('input[name="align"]').prop('checked', false);
<input type="radio" id="inlineRadio1" name="align" value="left"> Left
<input type="radio" id="inlineRadio1" name="align" value="center"> Center
<input type="radio" id="inlineRadio1" name="align" value="right"> Right
var ed=tinyMCE.get('article-content');//获取编辑器实例
var range=ed.selection.getRng();//射程
var newNode=ed.getDoc().createElement(“img”);//创建img节点
newNode.src=attachment.prop('src');
newNode.width=附件.width();
newNode.height=附件.height();
newNode.align=$('input[name=“align”]”)。val();//添加src属性
range.insertNode(newNode);
/*清除以前的值*/
$('input[name=“align”]”)。prop('checked',false);
左边
居中
赖特