【发布时间】:2019-10-02 20:50:24
【问题描述】:
我正在尝试使用 jquery 使电话号码可点击。有现有的 css 代码和 jquery 来创建 html,但是我似乎无法添加 href。
尝试将 span 类更改为包含 href,添加后电话号码不显示
jQuery(document).ready(function() {
$phone_number2 = "International 00-1-250-586-9928";
jQuery("span#et-info-phone").after("<span class=info-phone-2>" + $phone_number2 + "</span>");
jQuery(".info-phone-2").attr("href", "tel:00-1-250-586-9928");
});
span.info-phone-2 {
position: relative;
}
.info-phone-2:before {
position: relative;
top: 2px;
margin-right: 2px;
content: "\e090";
}
.info-phone-2 {
margin-right: 13px;
}
.info-phone-2:before {
font-family: "ETmodules" !important;
font-weight: normal;
font-style: normal;
font-variant: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
line-height: 1;
text-transform: none;
speak: none;
}
【问题讨论】:
-
跨度没有 href 属性,锚点有
-
将
span更改为a。 -
支点(忽略跨度问题);您正在使用字符串连接将文本添加到跨度。为什么不在那里连接 href 呢?
-
@Barmar 我这样做了,现在电话号码没有出现
-
请更新您的问题以显示您更新后的逻辑。
标签: jquery