效果预览:
程序代码:
<iframe id="editor" width="90%" height="100"></iframe> <script>editor.document.designMode="on";</script><input type="button" value="获取图片" onclick="getImg();" /> <script type="text/javascript"> <!-- function getImg() { var str_img = editor.document.body.innerHTML.replace(/[\s\S]*?src=[\'\"\s]*?(http:\/\/[a-z\d\._\-\/\%]*)[\'\"\s]*?/igm, '$1,'); var imgs = str_img.split(','); str_img = ''; for (var i=0;i<imgs.length-1;i++) { if (imgs[i].indexOf('http://')==0) { if (i>0)str_img += ','; str_img += imgs[i]; } } editor.document.body.innerHTML=(str_img); } //--> </script> |