[英]Hide button if mailto: is empty
I have a list of users and if they have an email they can click on a button to send an email.我有一个用户列表,如果他们有 email,他们可以单击按钮发送 email。 The thing is that I need to hide the EMAIL button if the user doesn't have a email.问题是,如果用户没有 email,我需要隐藏 EMAIL 按钮。
Here is what i have:这是我所拥有的:
<form action='/' method='get'>
<a href='mailto:<?=$user['email']?>'><button type="button" class="btn btn-dark btn-sm"><span>Email</span></button></a>
</form>
This is what i tryed but didn't work:这是我尝试但没有奏效的方法:
<a href='mailto:<?=$user['email']?>'><button id="sendmail" type="button" class="btn btn-dark btn-sm" onload="hideButton()"><span>Email</span></button></a>
<script type="text/javascript">
$(function(){
function hideButton(){
if(email === "mailto:"){
$("#sendmail").show();
}
else {
$("#sendmail").hide();
}
}
});
</script>
I don't know how to solve it.我不知道如何解决它。 I google this but most of the answers gives me an Error 500 when I upload to the website我用谷歌搜索,但是当我上传到网站时,大多数答案都会给我一个错误 500
You can do it directly in PHP just by wrapping it an if statement.您可以直接在 PHP 中执行此操作,只需将其包装为if语句即可。
<?php
if (isset($user['email']) && trim($user['email']) !== '') {
echo '<a href="mailto:' . $user['email'] . '">Send email</a>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.