- <html >
- <head>
- <title>无标题页</title>
- <script type="text/javascript" language="javascript">
- function prepareplaceholder(){
- urlinfo=window.location.href; //获取当前页面的url
- len=urlinfo.length;//获取url的长度
- offset=urlinfo.indexOf("?");//设置参数字符串开始的位置
- newsidinfo=urlinfo.substr(offset,len)//取出参数字符串 这里会获得类似“id=1”这样的字符串
- newsids=newsidinfo.split("=");//对获得的参数字符串按照“=”进行分割
- newsid=newsids[1];//得到参数值
- alert("您要传递的参数值是"+newsid);
- // document.getElementById("power").src=newsid;
- // document.images.power.src="ps05.gif";
- // document.getElementById("power").src=newsid;
- //alert("您要传递的参数值是"+newsid);
- var placeholder = document.createElement("img");//创建img元素节点
- placeholder.setAttribute("id","placeholder");
- placeholder.setAttribute("src",newsid);
- placeholder.setAttribute("alt","My lover yu");
- document.getElementsByTagName("body")[0].appendChild(placeholder);
- }
- window.onload = prepareplaceholder;
- </script>
- </head>
- <body >
- </body>
- </html>
如果是插在某个节点后面则参考 《DOM创建添加新节点》 这篇文章
另外一种方法
- <html >
- <head>
- <title>无标题页</title>
- <script type="text/javascript" language="javascript">
- urlinfo=window.location.href; //获取当前页面的url
- len=urlinfo.length;//获取url的长度
- offset=urlinfo.indexOf("?");//设置参数字符串开始的位置
- newsidinfo=urlinfo.substr(offset,len)//取出参数字符串 这里会获得类似“id=1”这样的字符串
- query=newsidinfo.split("&");
- dir=query[0].split("=");//对获得的参数字符串按照“=”进行分割
- picdir=dir[1];//得到参数值
- ahref=query[1].split("=");//对获得的参数字符串按照“=”进行分割
- hf=ahref[1];//得到参数值
- function prepareplaceholder(){
- var power=document.getElementById("content");
- power.innerHTML="<a href='" + hf + "' target='_blank'> <img src='"+picdir+"' width=200 height=30 border='0'></a>";
- }
- window.onload = prepareplaceholder;
- </script>
- </head>
- <body >
- <div id="content"></div>
- </body>
- < ml>