我通过一个简单的谷歌搜索找到了我的问题的答案,但是,我遇到了一个小问题。
到目前为止,我的HTML页面上有一个图像,其ID为newAvatar。 我试图通过它的ID找到这个图像,并将它的源保存到一个变量中,然后最终变成一个XML文档,以便以后使用。
当我将此源保存到变量中,或者将其警告以进行检查时,它会显示完整的源,这是不寻常的。 例如,我在WAMP服务器上运行我的站点,因此变量保存为:
http://localhost/uploads/newUploadedImage.jpg实际上,源代码应该简单明了,uploads / newUploadedImage.jpg
图片标签是
<img src="uploads/newUploadedImage.jpg" width="60px" height="60px;" id="newAvatar"/>我检查来源的方式是
alert(document.getElementById('newAvatar').src);任何想法如何摆脱第一批垃圾?
非常感谢所有帮助!
I found the answer to my question via a simple Google search, although, there is a slight problem that I ran into.
So far, I have an image on my HTML page with the ID of newAvatar. I am attempting to find this image via its ID, and save it's source into a variable, then eventually into an XML document to be used later on.
When I save this source into a variable, or alert it for checking purposes, it is displaying the full source, which is unusual. For example, I am running my site on a WAMP server, so the variable is saving as:
http://localhost/uploads/newUploadedImage.jpgWhen in reality, the source should be plain and simple, uploads/newUploadedImage.jpg
The image tag is
<img src="uploads/newUploadedImage.jpg" width="60px" height="60px;" id="newAvatar"/>The way i am checking the source is
alert(document.getElementById('newAvatar').src);Any idea how to get rid of the first lot of junk?
All help is greatly appreciated!
最满意答案
通过之前使用@DavidThomas评论,我设法让它工作。 这就是我将警报更改为:
alert(document.getElementById('newAvatar').getAttribute('src'));By using @DavidThomas comment before, I managed to get it working. This is what i changed my alert to:
alert(document.getElementById('newAvatar').getAttribute('src'));更多推荐
source,uploads,newUploadedImage,电脑培训,计算机培训,IT培训"/> <meta name=&qu
发布评论