[英]How to add alt to the image src tag in javascript execCommand methode?
'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);
}
}
},
I have code like this, i want to give alt to image, how can i achieve this? 我有这样的代码,我想给图像一个替代,我怎么能做到这一点? when i take the source i wan to see
<img src="smiley.gif" alt="Smiley face">
like this, Is it possible? 当我使用源代码时,希望看到这样的
<img src="smiley.gif" alt="Smiley face">
,这可能吗? please help me. 请帮我。
It seems that you can't do it with the execCommand directly Documentation of the commands an other one . 看来您不能直接使用execCommand 来完成该命令 的 文档 。
You can still do it in jQuery, after adding the image (seems a bit hackish, I know, but don't think you can do better) : 添加图像后,您仍然可以在jQuery中完成此操作(我知道,这似乎有些骇人听闻,但不要认为您可以做得更好):
$('img[src="smiley.gif"]').attr('alt','Smiley face');
您可以这样使用insertHTML命令:
document.execCommand('insertHTML', 0, '<img src="' + newUrlValue + '" alt="' + newAltValue + '" />');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.