Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在变量Json href属性中插入值?_Javascript_Html_Json - Fatal编程技术网

Javascript 如何在变量Json href属性中插入值?

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]来自

有一个问题我想在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]来自服务器端的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>