繁体   English   中英

通过 JQuery 添加 Href

[英]Adding Href Via JQuery

我正在尝试使用 jquery 使电话号码可点击。 有现有的 css 代码和 jquery 来创建 html,但是我似乎无法添加 href。

尝试更改跨度 class 以包含 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; }

使用锚点而不是跨度。

 jQuery(document).ready(function() { $phone_number2 = "International 00-1-250-586-9928"; jQuery("span#et-info-phone").after("<a class=info-phone-2>" + $phone_number2 + "</a>"); jQuery(".info-phone-2").attr("href", "tel:00-1-250-586-9928"); });
 a.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; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <span id="et-info-phone">Phone: </span>

暂无
暂无

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

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