我有一个带有以下 html 的页面,该页面使用不同的电话号码多次出现:
<div class="crm-content crm-contact_phone primary">
<span>5555551212</span>
</div>
电话号码本身使用 {$phone.i.phone} 形式的 smarty 变量显示,其中 i 是电话号码数组中的数组键。
我希望能够使用 js 更改这些电话号码的格式。
因此,对于一个电话号码,我在我的 smarty .tpl 文件中使用了以下内容:
{literal}
cj(function($){
var phoneNumber = {/literal}{$phone.1.phone}{literal};
var phoneNumberFormatted = '(' + phoneNumber.substr(0,3) + ') ' + phoneNumber.substr(3,3) + '-' + phoneNumber.substr(6);
$(".crm-contact_phone span").text(phoneNumberFormatted);
});
{/literal}
所以我想,我需要做一些事情:
$('.crm-contact_phone span').each(function(i, obj) {
var phoneNumber = '' + {/literal}{$phone.1.phone}{literal};
}
但我不知道如何用 javascript 索引 i 替换 smarty 变量中的 1。
有任何想法吗?谢谢。