简体   繁体   English

单击以显示电话号码并单击以拨打电话

[英]Click to show phone number and click to call

I need to create function:我需要创建功能:

1) show hidden html (phone number) on click 1)点击显示隐藏的html(电话号码)

2) After mobile number shown it must be clickable so we can call via mobile 2) 显示手机号码后必须是可点击的,以便我们可以通过手机拨打

Here's my code:这是我的代码:

<div class="category-list-title">
  <h5>
   <a href="javascript:void(0)" class="number" data-last="<?php echo get_post_meta($pid, '_carspot_poster_contact', true ); ?>">
    <span><?php echo esc_html__('Click to View', 'carspot' ); ?>
    </span>
   </a>
  </h5>
</div>

You only need the php to get the data, in this case the phone number.您只需要 php 即可获取数据,在本例中为电话号码。

So this is not a php question, but a html and javascript...所以这不是一个 php 问题,而是一个 html 和 javascript ......

So, here's an example:所以,这是一个例子:

HTML: HTML:

<div class="category-list-title">
<a id="show" href="#" onclick="show();">View phone</a><br>
<!-- Similar to mailto you tel in html this will allow you to make a call directly -->
<a id="phone" href="tel:555-555-5555">555-555-5555</a>
</div>

CSS: CSS:

#phone {
  display: none;
}

JavaScript: JavaScript:

document.getElementById("show").onclick = function() {show()};

function show() {
  document.getElementById("phone").style.display="block";
}

OR jQuery:或 jQuery:

$('#show').click(function(){$('#phone').show();});

JSFiddle of the example: https://jsfiddle.net/bm93s2Lc/2/示例的 JSFiddle: https ://jsfiddle.net/bm93s2Lc/2/

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

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