如果未输入URL,则隐藏按钮

Hide Button if no URL entered

本文关键字:隐藏 按钮 URL 未输 输入 如果      更新时间:2024-03-28

我的按钮有问题。

当我没有输入URl到我身边的帖子时;转到站点";。但当我没有输入URL时,按钮会显示出来。

如果没有输入URL,有人能告诉我如何隐藏按钮吗?

这是来自按钮的代码:

<?php
/**
 * Coupon Code Box content - Generic/Promotion.
 *
 * @package Clipper'Templates
 * @author  AppThemes
 * @since   Clipper 1.6
 */
?>
<?php /*?><h5><?php _e( 'Promo:', RW_CP_TD ); ?></h5>
<?php */?>
<div class="couponAndTip">
<div class="link-holder">
    <a href="<?php echo clpr_get_coupon_out_url( $post ); ?>" id="coupon-link-<?php echo $post->ID; ?>" 
    class="coupon-code-link affiliates-link" target="_blank" data-clipboard-text="<?php _e( 'Click to Redeem', RW_CP_TD ); ?>">
    <span><?php _e( 'Click to Redeem', RW_CP_TD ); ?></span></a>
</div> <!-- #link-holder -->
</div><!-- /couponAndTip -->

请在此处查看此JSFiddle。

您所需要做的就是替换按钮id和输入框id,并将jQuery添加到索引页面中。

HTML:

<input id="input" type="text">
<button id="btn">Go to URL</button>

JavaScript:

$('#input').on('keyup', function(){
    var visibility;
  if ($(this).val().length === 0) {
    visibility = 'inline';
  } else {
    visibility = 'none';
  }
    $('#btn').css('display', visibility);
})
<?php
/**
 * Coupon Code Box content - Coupon Code.
 *
 * @package Clipper'Templates
 * @author  AppThemes
 * @since   Clipper 1.6
 */
global $clpr_options;
$coupon_code = wptexturize( get_post_meta( $post->ID, 'clpr_coupon_code', true ) );
$button_text = ( $clpr_options->coupon_code_hide ) ? __( 'Show Coupon', RW_CP_TD ) : $coupon_code;?>
<?php if(clpr_get_coupon_out_url( $post ) != '') : ?>
<div class="couponAndTip">
 <div class="link-holder">
    <a href="<?php echo clpr_get_coupon_out_url( $post ); ?>" id="coupon-link-<?php echo $post->ID; ?>" class="coupon-code-link test" target="_blank" data-clipboard-text="<?php echo $coupon_code; ?>">
        <span><?php echo $button_text; ?></span>
    </a>
 </div> <!-- #link-holder -->
</div><!-- /couponAndTip -->
<?php endif; ?>

只需放置该控制结构来检查该url是否为空