Javascript 如何在变量Json href属性中插入值?
有一个问题我想在href link中加入一个变量,但不使用代码,这是在直接链接创建中 示例如下:Javascript 如何在变量Json href属性中插入值?,javascript,html,json,Javascript,Html,Json,有一个问题我想在href link中加入一个变量,但不使用代码,这是在直接链接创建中 示例如下: <a href="http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_COD_UNI=" + [CODIGO_RASTREAMENTO] targert="_blank">código de rastreamento</a> 变量[CODIGO_RASTREAMENTO]来自
<a href="http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_COD_UNI=" + [CODIGO_RASTREAMENTO] targert="_blank">código de rastreamento</a>
变量[CODIGO_RASTREAMENTO]来自服务器端的Json文件
注意:我不能使用脚本。对于内联,您的选择非常有限。例如,您可以使用onmouseover事件动态地用变量值替换占位符 假设你有以下链接
<a href="http://www.google.com/search?q=CODIGO_RASTREAMENTO" target="_blank">
Search
</a>
您可以将上面的链接修改为
<a href="http://www.google.com/search?q=CODIGO_RASTREAMENTO"
onmouseover="this.href = this.href.replace('CODIGO_RASTREAMENTO', CODIGO_RASTREAMENTO)"
target="_blank">
Search
</a>
它将占位符替换为实际值,因此当您实际单击链接时,值将生效
演示:我不能使用标签脚本必须是内联的
<a href="http://www.google.com/search?q=CODIGO_RASTREAMENTO"
onmouseover="this.href = this.href.replace('CODIGO_RASTREAMENTO', CODIGO_RASTREAMENTO)"
target="_blank">
Search
</a>