简体   繁体   English

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

[英]How to insert value in a variable Json href attribute?

One question I wanted to put a variable inside href link not using code, which is in direct link creation. 我想在不使用代码的情况下在href链接中放入一个变量,这是直接链接创建中的一个问题。

The example is below: 示例如下:

<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>

variable [CODIGO_RASTREAMENTO] comes from a Json file this on the server side. 变量[CODIGO_RASTREAMENTO]来自服务器端的Json文件。

Note: I can not use scripts . 注意:我不能使用脚本

For inline your choice is really limited. 对于内联,您的选择确实很有限。 For example you can use "onmouseover" event to replace placeholder with variable value on the fly. 例如,您可以使用“ onmouseover”事件动态地将占位符替换为变量值。

Let's say you have following link 假设您有以下链接

<a href="http://www.google.com/search?q=CODIGO_RASTREAMENTO" target="_blank">
  Search
</a>

In that case "CODIGO_RASTREAMENTO" is just a placeholder. 在这种情况下,“ CODIGO_RASTREAMENTO”只是一个占位符。 At some point variable CODIGO_RASTREAMENTO gets assigned, eg CODIGO_RASTREAMENTO会分配变量CODIGO_RASTREAMENTO ,例如

var CODIGO_RASTREAMENTO = 'stackoverflow';

You can modify the above link to 您可以将以上链接修改为

<a href="http://www.google.com/search?q=CODIGO_RASTREAMENTO"
   onmouseover="this.href = this.href.replace('CODIGO_RASTREAMENTO', CODIGO_RASTREAMENTO)" 
   target="_blank">
      Search
</a>

It replaces placeholder with a real value, so when you actually click the link - value takes effect. 它用实际值替换占位符,因此当您实际单击链接时-值生效。

Demo: http://jsfiddle.net/5v2S9/ 演示: http//jsfiddle.net/5v2S9/

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

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