如何将XSL变量作为参数传递给script标签内的JavaScript函数?

4
我尝试了以下代码:
<xsl:variable name="xx" select="'40967.6424503935'"/>
<script type="text/javascript">
   time({$xx});
</script>

我的意图是通过time()中的document.write()来显示文本。但它没有给出任何结果。

3个回答

6
花括号用于“属性值模板”,但在此情况下,您并未创建属性,而只是一个普通的文本节点。我认为您需要做类似于这样的事情:
<xsl:variable name="xx" select="'40967.6424503935'"/>
<script type="text/javascript">
   time(<xsl:value-of select="$xx" />);
</script> 

我已经把它做成了这样:var curDate = "<xsl:value-of select="$date"/>"; document.write('<span style="font-size:10px;font-family: arial;font-weight:bold;">['+time(curDate)+"]</span>"); - semantic_c0d3r

1
在上面的代码片段中应该有一个小修正。参数应该在单引号内传递。
<xsl:variable name="xx" select="'40967.6424503935'"/>
<script type="text/javascript">
   time('<xsl:value-of select="$xx" />');
</script> 

这将会起作用。


0
<input type="hidden" id="title" select="{COL[@name='title']}"/>

<script type="text/javascript">
    alert(document.getElementById('title').value);
</script>

这对我有效。


1
您的答案可以通过添加更多支持信息来改进。请[编辑]以添加进一步详细信息,例如引用或文档,以便其他人可以确认您的答案正确无误。您可以在帮助中心中找到有关编写良好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接