如果 mailto: 为空则隐藏按钮
Hide button if mailto: is empty
我有一个用户列表,如果他们有电子邮件,他们可以单击按钮发送电子邮件。问题是如果用户没有电子邮件,我需要隐藏 EMAIL 按钮。
这是我的:
<form action='/' method='get'>
<a href='mailto:<?=$user['email']?>'><button type="button" class="btn btn-dark btn-sm"><span>Email</span></button></a>
</form>
这是我尝试过但没有奏效的方法:
<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>
不知道怎么解决。我 google 这个但是大多数答案在我上传到网站时给我一个错误 500
您可以直接在 PHP 中执行此操作,只需将其包装在 if 语句中即可。
<?php
if (isset($user['email']) && trim($user['email']) !== '') {
echo '<a href="mailto:' . $user['email'] . '">Send email</a>';
}
我有一个用户列表,如果他们有电子邮件,他们可以单击按钮发送电子邮件。问题是如果用户没有电子邮件,我需要隐藏 EMAIL 按钮。
这是我的:
<form action='/' method='get'>
<a href='mailto:<?=$user['email']?>'><button type="button" class="btn btn-dark btn-sm"><span>Email</span></button></a>
</form>
这是我尝试过但没有奏效的方法:
<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>
不知道怎么解决。我 google 这个但是大多数答案在我上传到网站时给我一个错误 500
您可以直接在 PHP 中执行此操作,只需将其包装在 if 语句中即可。
<?php
if (isset($user['email']) && trim($user['email']) !== '') {
echo '<a href="mailto:' . $user['email'] . '">Send email</a>';
}