[英]Setting image src with getElementById(“”).src won't work in xsl
我有以下脚本:
<script language="text/javascript">
document.getElementById("eagle").src="http://path.com:8000/OA_HTML/1.gif";
</script>
和html:
<img id="eagle" src="godlo.gif" width="60" height="60"/>
我不会用JS更改图像的路径,但保持不变。 为什么不起作用? 在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>
您的脚本不知道eagle
在哪里,请将您的脚本放在img
标签下面。 还需要将<script language="text/javascript">
更改为<script type="text/javascript">
<?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>
@Ishank Gupta在评论中发布的解决方案是正确的:
将<script language="text/javascript">
更改为<script type="text/javascript">
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.