日期:2014-05-16  浏览次数:20318 次

急啊,救命的,再不做出来就被炒了
各位高手,今天我在用这个方法的时候老是出错,添加不了图片。不知道怎么回事下面是我试过的方法。
<html>
<head   id= "Head1 "   runat= "server ">
        <title> 无标题页 </title>
        <script   type= "text/javascript ">
        function   addpic()
        {
                var   frame1   =   document.getElementById( "frame1 ");
                frame1.designMode   =   "on ";
                frame1.focus();
                var   imgUrl   =   encodeURI( "C:\Documents   and   Settings\All   Users\Documents\My   Pictures\Blue   hills.jpg ");
                var   ses   =     frame1.document.execCommand( "insertimage ",false,imgUrl);
                debugger;//frame1.all.img1.src= "C:\Documents   and   Settings\All   Users\Documents\My   Pictures\Blue   hills.jpg ";
                frame1.focus();
        }
        </script>
</head>
<body>
        <form   id= "form1 "   runat= "server ">
        <div>
                <input   id= "button2 "   type= "button "   onclick= "addpic(); "   value= "button2 "   />
                <input   id= "button1 "   type= "button "   onclick= "addpic(); "   value= "button1 "   />
                <iframe   id= "frame1 "   src= "about:blank "   width= "400 "   height= "400 "   />
</body>
</html>
这个是后来看到的,之前我没有对imagepath进行编码,但是也加不上去。如果我用
execCommand( "insertimage ",true,null),加的图片没有到我的iframe里面,这个是怎么回事啊?

------解决方案--------------------
<iframe id= "Editor " marginwidth=1 scrolling= "auto " style= "height:150px;width:100%;background-color:white; "> </iframe>
<script>
var doc;
doc=document.frames.Editor.document;
doc.designMode = "On ";
window.setTimeout( 'Editor.focus() ',100);

function doInsertImage(){
Editor.focus();
doc.execCommand( 'InsertImage ',false, 'C:/Documents and Settings/Administrator/桌面/new.gif ');
}
</script>
<button onclick= "doInsertImage() "> gogogogogo </button>

试下这个