1

因此,我使用JSColor 选择器结合document.execCommand方法更改所选文本的前景,您可以在其中发送命令,如下所示:

<input maxlength="5" class="color {required:false}" onchange="fmtEdit('Icontent','ForeColor',this.color)">

fmtEdit 函数如下所示:

function fmtEdit(I,command, optn, evnt){
 if((command=='forecolor') || (command=='hilitecolor')){
  this.getPallete(command, optn, evnt);
 }else{
  if($(I).contentWindow.document.queryCommandEnabled(command)){
   $(I).contentWindow.document.execCommand(command, false, optn);
   return true;
  }else return false;
 }
 $(I).contentWindow.focus();
}

如果我从带有 onClick 事件的按钮或图像发送命令,则代码可以正常工作,例如:

<img alt="Bold" title="Bold" class="butClass" src="bold.png" onClick="fmtEdit('Icontent','bold','')">

但是,一旦我单击颜色选择器字段以选择颜色,所选文本就会失去焦点。

当我点击颜色选择器时,有没有办法保持对所选文本的选择?

非常感谢!加布斯特。

4

0 回答 0