通过JQuery添加Href

通过JQuery添加Href,jquery,Jquery,我正在尝试使用jquery使电话号码可点击。有现有的css代码和jquery来创建html,但是我似乎不能添加href 尝试将span类更改为包含href,添加时电话号码不会显示 jQuery(文档).ready(函数(){ $phone_number2=“国际00-1-250-586-9928”; jQuery(“span#et info phone”)。在(“+$phone_number2+”)之后; jQuery(“.info-phone-2”).attr(“href”,“电话:00-1

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

尝试将span类更改为包含href,添加时电话号码不会显示

jQuery(文档).ready(函数(){
$phone_number2=“国际00-1-250-586-9928”;
jQuery(“span#et info phone”)。在(“+$phone_number2+”)之后;
jQuery(“.info-phone-2”).attr(“href”,“电话:00-1-250-586-9928”);
});
span.info-phone-2{
位置:相对位置;
}
.info-phone-2:之前{
位置:相对位置;
顶部:2个;
右边距:2px;
内容:“\e090”;
}
.info-phone-2{
右边距:13px;
}
.info-phone-2:之前{
字体系列:“ETmodules”!重要;
字体大小:正常;
字体风格:普通;
字体变体:正常;
-webkit字体平滑:抗锯齿;
-moz osx字体平滑:灰度;
线高:1;
文本转换:无;
说:没有;

}
使用锚而不是跨度

jQuery(文档).ready(函数(){
$phone_number2=“国际00-1-250-586-9928”;
jQuery(“span#et info phone”)。在(“+$phone_number2+”)之后;
jQuery(“.info-phone-2”).attr(“href”,“电话:00-1-250-586-9928”);
});
a.info-phone-2{
位置:相对位置;
}
.info-phone-2:之前{
位置:相对位置;
顶部:2个;
右边距:2px;
内容:“\e090”;
}
.info-phone-2{
右边距:13px;
}
.info-phone-2:之前{
字体系列:“ETmodules”!重要;
字体大小:正常;
字体风格:普通;
字体变体:正常;
-webkit字体平滑:抗锯齿;
-moz osx字体平滑:灰度;
线高:1;
文本转换:无;
说:没有;
}


电话:
span没有href属性,将
span
更改为
a
。侧点(忽略span问题);您正在使用字符串连接将文本添加到跨度中。为什么不在那里连接href?@Barmar我这样做了,现在电话号码没有出现。请更新您的问题以显示更新的逻辑。