在此链接上:https://www.equilibriumtherapy.pt/artemisa.html我打算有一个“单击以显示”文本元素。
我正在使用的脚本无法正常工作。如果单击该元素,此后该页面上将没有其他链接。您必须重新加载才能浏览此页面。
.click函数似乎在第一次单击后就抓住了所有鼠标单击!
请帮助我。
谢谢
<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function () {
var n = 0;
var i = 0;
var phone = "+351919260713";
var format = phone.slice(0,4)+" "
+phone.slice(4,7)+" "
+phone.slice(7,10)+" "
+phone.slice(10,13)+" ";
var hidden = format.slice(0,12)+" XXX";
$('.phoneNo').text(hidden);
//
$('.phoneWrap').click(function(e){
// $('.phoneWrap').focus(function(){
// var location = $('a').attr("href");
$("a").removeAttr('href');
$('.phoneNo').text(format);
$('.phoneLabel').text("(Clica para Ligar)");
// $('.aux').text(n);
if(n>=1){
$("a").attr("href", "tel:"+phone);
// $("a").attr("href", "null");
}
++n;
return 0;
// });
});
//$('.aux2').text("exited "+i);
++i;
});
</script>
<style>
body{
font-family: montserrat,sans-serif;
font-size: .8em;
letter-spacing: -.02em;
display: block;
}
div.phoneWrap {
line-height: normal;
}
div.phoneWrap .phoneNo {
font-weight: 700;
font-size: 1.2em;
}
a{
margin-top: 4px;
background-color: transparent;
width: 100%;
border: none;
padding: 5px 0;
font-size: 1.6em;
line-height: 1.8em;
color: #ffffff;
border: none;
text-decoration: none;
display: block;
text-align: center;
cursor: pointer;
}
</style>
</head>
<body>
<a>
<i></i>
<div class="phoneWrap">
<div class="phoneNo"></div>
<div class="phoneLabel">(Clica para ver Telefone)</div>
<div class="aux"></div>
<div class="aux2"></div>
</div>
</a>
</body>
</html>
编辑
我找到了解决方法!
代码如下:
<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function () {
var n = 0;
var i = 0;
var phone = "+351919260713";
var format = phone.slice(0,4)+" "
+phone.slice(4,7)+" "
+phone.slice(7,10)+" "
+phone.slice(10,13)+" ";
var hidden = format.slice(0,12)+" XXX";
$('.phoneNo').text(hidden);
$('.phoneWrap').click(function(e){
$("#clk_link").removeAttr('href');
$('.phoneNo').text(format);
$('.phoneLabel').text("(Clica para Ligar)");
// $('.aux').text(n);
if(n>=1){
$("#clk_link").attr("href", "tel:"+phone);
}
++n;
}); //close .click
//$('.aux2').text("exited "+i);
++i;
}); //Close document ready
</script>
<style>
body{
font-family: montserrat,sans-serif;
font-size: .8em;
letter-spacing: -.02em;
display: block;
}
div.phoneWrap {
line-height: normal;
}
div.phoneWrap .phoneNo {
font-weight: 700;
font-size: 1.2em;
}
#clk_link{
margin-top: 4px;
background-color: transparent;
width: 100%;
border: none;
padding: 5px 0;
font-size: 1.6em;
line-height: 1.8em;
color: #ffffff;
border: none;
text-decoration: none;
display: block;
text-align: center;
cursor: pointer;
}
</style>
</head>
<body>
<a href="#" id="clk_link">
<i></i>
<div class="phoneWrap">
<div class="phoneNo"></div>
<div class="phoneLabel">(Clica para ver Telefone)</div>
<div class="aux"></div>
<div class="aux2"></div>
</div>
</a>
</body>
</html>