简体   繁体   English

<a href =中的var(使用javascript从XML文件中获取)

[英]var (taken from a xml file, with a javascript) in a < a href=

I repost the question (i deleted what i did before, because, my fault, i was not enough clear, i'm deeply sorry). 我重新发布了问题(我删除了之前的操作,因为我的错,我不够清楚,非常抱歉)。

I have this var: 我有这个变种:

var telefono = $(this).find('Telefono').text();

This "Telefono" is a number, taken from a xml file, with a javascript. 这个“ Telefono”是一个数字,取自带有javascript的xml文件。 I don't post all the function, but if you think it helps, let me know. 我没有发布所有功能,但是如果您认为有帮助,请告诉我。

I need to put this var inside a button. 我需要将此变数放在按钮内。 It's a button for a mobile website (in jquery), with the command "tel" (it uses the number beetween the { } to make a call): 这是一个用于移动网站的按钮(在jquery中),使用命令“ tel”(它使用{}之间的数字进行呼叫):

< a target = "_blank " href = " tel:{{"telefono"}} " data-role="button" >

I don't find the right way to write the var in the button. 我找不到在按钮中编写var的正确方法。

Can you help me? 你能帮助我吗?

You can do this : 你可以这样做 :

$('a[href~="tel:{{telefono}}"]').attr('href', 'tel:'+telefono);

If you want something more generic, that is you want to replace {{telefono}} in all your attributes href , you could use this : 如果您想要更通用的东西,那就是要在所有属性href替换{{telefono}} ,则可以使用以下命令:

$('[href~="{{telefono}}"]').attr('href', function(i, v) {
   return v.replace('{{telefono}}', telefono);
});

EDIT : 编辑:

If you also want to change the content of the a element, you can do this : 如果您还想更改a元素的内容,则可以执行以下操作:

$('[href~="{{telefono}}"]').attr('href', function(i, v) {
   return v.replace('{{telefono}}', telefono);
}).html(telefono);

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

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