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