简体   繁体   English

如何使用HTML或javascript将变量传递到action属性以进行下载(按钮/链接),

[英]How can i pass a variable into action attribute for download (button/link) using HTML or javascript,

<xsl:template name ="DLFiles">
  <xsl:variable name ="FilePath" select="@FilePath"/>    
  <form method="get" action="$FilePath">
        <button type="submit">Download</button>

(FilePath comes from a SQL column) (FilePath来自SQL列)

when $FilePath is a hardcoded (local) file path, this works great. 当$ FilePath是硬编码(本地)文件路径时,这很好用。 However when a variable is passed, the download does not work (the file path can not be found, cant get data(FilePath column data) from SQL) 但是,当传递变量时,下载将不起作用(无法找到文件路径,无法从SQL获取数据(FilePath列数据))

is there something I can change in the above code to make this work correctly in this instance? 我可以在上面的代码中进行一些更改以使它在这种情况下正常工作吗?

You can use Attribute Value Templates here if you want to use a variable in an attribute 如果要在属性中使用变量,可以在此处使用“ 属性值模板”

 <form method="get" action="{$FilePath}">

The curly braces indicate an expression to be evaluated, not output literally. 花括号指示要计算的表达式,而不是按字面值输出。

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

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