简体   繁体   English

如何在脚本标签内将 xsl 变量作为参数传递给 javascript function?

[英]How to pass xsl variable as a parameter to javascript function within script tag?

I have tried the following code:我尝试了以下代码:

<xsl:variable name="xx" select="'40967.6424503935'"/>
<script type="text/javascript">
   time({$xx});
</script>

My intention is to display text via document.write() present in time().我的意图是通过 time() 中的 document.write() 显示文本。 But it didnt give any result.但它没有给出任何结果。

The curly braces are for 'Attribute Value Templates', but in this case you are not creating an attribute here, just a normal text node. 花括号用于“属性值模板”,但在这种情况下,您不是在此处创建属性,而只是普通文本节点。 I think you need to do something like this 我想你需要做这样的事情

<xsl:variable name="xx" select="'40967.6424503935'"/>
<script type="text/javascript">
   time(<xsl:value-of select="$xx" />);
</script> 

There should be a small correction in the above code snippet. 上面的代码片段应该有一个小的修正。 The parameter should be passed within single inverted comma. 该参数应在单个倒置逗号内传递。

<xsl:variable name="xx" select="'40967.6424503935'"/>
<script type="text/javascript">
   time('<xsl:value-of select="$xx" />');
</script> 

This will work. 这会奏效。

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

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

This works for me.这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM