Javascript 使用getElementById(";)设置图像src.src-won';不能在xsl中工作
我有以下脚本:Javascript 使用getElementById(";)设置图像src.src-won';不能在xsl中工作,javascript,html,xslt,xslt-1.0,Javascript,Html,Xslt,Xslt 1.0,我有以下脚本: <script language="text/javascript"> document.getElementById("eagle").src="http://path.com:8000/OA_HTML/1.gif"; </script> document.getElementById(“eagle”).src=”http://path.com:8000/OA_HTML/1.gif"; 和html: <
<script language="text/javascript">
document.getElementById("eagle").src="http://path.com:8000/OA_HTML/1.gif";
</script>
document.getElementById(“eagle”).src=”http://path.com:8000/OA_HTML/1.gif";
和html:
<img id="eagle" src="godlo.gif" width="60" height="60"/>
我不会改变图像的路径,但会保持不变。
为什么这样不行?在js fidle中,它工作得非常好,那么为什么在xslt中不能工作呢?
也许有办法
更新
我编辑了这篇文章来添加xsl文件。虽然我认为这里没有必要
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="html"/>
<xsl:template match="*">
<html>
<head>
<title>D</title>
</head>
<script language="text/javascript">
document.getElementById("eagle").src="http://example.com:8000/OA_HTML/1.gif";
</script>
<body>
<p style="text-align:center;"><img id="eagle" src="1.gif" width="60" height="60"/></p>
</body>
</html>
</xsl:template>
D
document.getElementById(“eagle”).src=”http://example.com:8000/OA_HTML/1.gif";
您的脚本不知道鹰在哪里,请将脚本放在img
标记下方。还需要将
更改为
D
var picurl=window.location.protocol+“/”+window.location.hostname+“/OA_HTML/godlo.gif/>”;
document.getElementById(“eagle”).src=”http://example.com:8000/OA_HTML/1.gif";
由@Ishank Gupta在评论中发布的解决方案是正确的:
将
更改为
成功了。你说的“行不通”是什么意思?元素是否由getElementById
返回?您到底观察到了什么?图像的Src仍然是/godlo.gif。请显示更多上下文。即XSLT样式表和正在转换的XML。好的,我更新了postTry,将
更改为
有关此问题的更多信息:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="html"/>
<xsl:template match="*">
<html>
<head>
<title>D</title>
</head>
<body>
<p style="text-align:center;"><img id="eagle" src="1.gif" width="60" height="60"/></p>
</body>
<script type="text/javascript">
var picurl = window.location.protocol+"//"+window.location.hostname+"/OA_HTML/godlo.gif/>";
document.getElementById("eagle").src="http://example.com:8000/OA_HTML/1.gif";
</script>
</html>
</xsl:template>