日期:2014-05-20  浏览次数:20569 次

在一个页面上根据已有的坐标添加图片
在页面A上根据页面B提供的坐标,在页面A中对应的坐标上添加一张20*20的图片。
问题的来源是:http://community.csdn.net/Expert/topic/5317/5317272.xml?temp=.4983026
请大家务必要看看,谢谢大家的帮助

------解决方案--------------------
document.getElementById( "imgid ").style.position= "absolute "
document.getElementById( "imgid ").style.left= "10px "
document.getElementById( "imgid ").style.top= "300px "

例如
------解决方案--------------------
A.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN "
"http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
<script type= "text/javascript ">
function addPic()
{
var win=window.showModalDialog( 'B.htm ');
var x=win[0];
var y=win[1];
var imgEle=document.createElement( "img ");
imgEle.setAttribute( "width ", "20 ");
imgEle.setAttribute( "height ", "20 ");
imgEle.setAttribute( "src ", "kk.gif ");
var di=document.getElementById( "mypicDiv ");
di.appendChild(imgEle);
}
</script>
</head>

<body>
<form name= "form1 " method= "post " action= " ">
<input type= "button " name= "Submit " value= "添加图片 " onClick= "addPic() ">
<div id= "mypicDiv "> </div>
</form>
</body>
</html>


B.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN "
"http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
<script type= "text/javascript ">
function goPic()
{
var tA=document.getElementById( "txtX ");
var tB=document.getElementById( "txtY ");
var a=new Array(tA.value,tB.value);
window.returnValue=a;
opener=null;
window.close();
}
</script>
</head>

<body>
<form name= "form1 " method= "post " action= " ">
<p> X坐标:
<input name= "txtX " type= "text " id= "txtX " on>
</p>
<p> Y坐标:
<input name= "txtY " type= "text " id= "txtB ">
</p>
<p>
<input type= "button " name= "Submit " value= "确定 " onClick= "goPic() ">
</p>
</form>
</body>
</html>