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

innerHTML为什么会自动添加“http://localhost/”?
function   UploadImage(url1,url2)
{
        alert(parent.IframeID.document.body.innerHTML);//位置1
        parent.IframeID.document.body.innerHTML   += ' <a   href= " '   +   url1   +   ' "   target= "_blank "> <img   src= " '   +   url2   +   ' "   border= "0 "   alt= "点击新窗口查看原始图片 "   type= "upload "/> </a> <br> </br> ';
      alert(parent.IframeID.document.body.innerHTML);//位置2
}

当url1= "/Images/a.jpg "时,位置1,输出 " ";
位置2居然输出 " <a   href= 'http://localhost/Images/a.jpg '   target=....... "
为什么会自动加上“http://localhost/”,有没有办法可以让它不要加,我期望得到的是 " <a   href= 'Images/a.jpg '   target=....... "


------解决方案--------------------
前面有一个/ 表示相对路径

读取的时候 html是ie解吸后的
实际的值就是 'http://localhost/Images/a.jpg
------解决方案--------------------
浏览器加不加前缀对你有影响吗?如果你在代码里面获得属性值,可以用下面的方式:
iFlags = 2

说明:
==========================
vAttrValue = object.getAttribute(sAttrName [, iFlags])
Parameters

sAttrName Required. String that specifies the name of the attribute.
iFlags Optional. Integer that specifies one or more of the following flags: 0 Default. Performs a property search that is not case-sensitive, and returns an interpolated value if the property is found.
1 Performs a case-sensitive property search. To find a match, the uppercase and lowercase letters in sAttrName must exactly match those in the attribute name. If the iFlags parameter for getAttribute is set to 1 and this option is set to 0 (default), the specified property name might not be found.
2 Returns the value exactly as it was set in script or in the source document.


------解决方案--------------------
上面都不行了,
src本就是一个路径的,
一个完整路径的,
不能取到你想要的值,不过人可以换一种方式 来作

------解决方案--------------------
取值的时候最好用document.getElementByID( "XXX ")