'insert_img': {
"text": "Inserimage",
"icon":"icon icon-picture",
"tooltip": "Insertimage",
"commandname":null,
"custom": function(){
var imgSrc = prompt('Enter image location', '');
if (imgSrc != null) {
document.execCommand('insertimage', false, imgSrc);
}
}
},
我有这样的代码,我想给图像添加alt,我该怎么做到这一点?当我拿这个来源我想看到<img src="smiley.gif" alt="Smiley face">
这样的时候,有可能吗?请帮帮我。
答案 0 :(得分:1)
您似乎无法直接使用execCommand Documentation of the commands an other one执行此操作。
在添加图像之后你仍然可以在jQuery中执行它(看起来有点hackish,我知道,但不认为你可以做得更好):
$('img[src="smiley.gif"]').attr('alt','Smiley face');
答案 1 :(得分:0)
您可以像这样使用insertHTML命令:
document.execCommand('insertHTML', 0, '<img src="' + newUrlValue + '" alt="' + newAltValue + '" />');