我希望按钮隐藏,当它为空时仍然不幸只有HTML之前,即使按钮已经是空的,我怎么能重写代码以便隐藏按钮?我发布了更多细节,也许有人可以帮助我
function cspm_infobox_content(){
$post_id = esc_attr($_POST['post_id']);
$infobox_type = esc_attr($_POST['infobox_type']);
$map_id = esc_attr($_POST['map_id']);
$status = esc_attr($_POST['status']);
$carousel = esc_attr($_POST['carousel']);
$telnr = get_post_meta( $post_id, 'telnr', true );
$telnr1 = get_post_meta( $post_id, 'telnr1', true );
$email = get_post_meta( $post_id, 'email', true );
$hane = get_post_meta( $post_id, 'hane', true );
$marte = get_post_meta( $post_id, 'marte', true );
$merkure = get_post_meta( $post_id, 'merkure', true );
$enjte = get_post_meta( $post_id, 'enjte', true );
$premte = get_post_meta( $post_id, 'premte', true );
$shtune = get_post_meta( $post_id, 'shtune', true );
$djele = get_post_meta( $post_id, 'djele', true );
$shteti = get_post_meta( $post_id, 'shteti', true );
$qyteti = get_post_meta( $post_id, 'qyteti', true );
$rajoni = get_post_meta( $post_id, 'rajoni', true );
$rruganr = get_post_meta( $post_id, 'rruganr', true );
$no_title = array(); // Infoboxes to display with no title
$no_link = array(); // Infobox to display whit no link
$no_description = array('square_bubble', 'rounded_bubble', 'cspm_type2', 'cspm_type3', 'cspm_type4'); // Infoboxes to display with no description
$no_image = array('cspm_type4'); // Infoboxes to display with no image
if(!in_array($infobox_type, $no_title)) $item_title = apply_filters('cspm_custom_infobox_title', stripslashes_deep($this->cspm_items_title($post_id, $this->items_title)), $post_id);
if(!in_array($infobox_type, $no_description)) $item_description = apply_filters('cspm_custom_infobox_description', stripslashes_deep($this->cspm_items_details($post_id, $this->items_details)), $post_id);
if(!in_array($infobox_type, $no_link)) $the_permalink = $this->cspm_get_permalink($post_id);
if(!in_array($infobox_type, $no_image)){
if($infobox_type == 'square_bubble' || $infobox_type == 'rounded_bubble')
$parameter = array( 'style' => "width:50px; height:50px;" );
elseif($infobox_type == 'cspm_type1')
$parameter = array( 'style' => "width:100px; height:80px;" );
elseif($infobox_type == 'cspm_type2')
$parameter = array();
elseif($infobox_type == 'cspm_type3' || $infobox_type == 'cspm_type5')
$parameter = array( 'style' => "width:60px; height:60px;" );
elseif($infobox_type == 'cspm_type4')
$parameter = array();
if($infobox_type == 'square_bubble' || $infobox_type == 'rounded_bubble'){
$infobox_thumb = get_the_post_thumbnail($post_id, 'cspacing-marker-thumbnail', $parameter);
}elseif($infobox_type == 'cspm_type1'){
$infobox_thumb = get_the_post_thumbnail($post_id, 'cspacing-infobox1-thumbnail', $parameter);
}else $infobox_thumb = get_the_post_thumbnail($post_id, 'cspacing-horizontal-thumbnail', $parameter);
if(empty($infobox_thumb))
$infobox_thumb = get_the_post_thumbnail($post_id, 'cspacing-horizontal-thumbnail', $parameter);
}
$post_thumbnail = apply_filters('cspm_infobox_thumb', $infobox_thumb, $post_id, $infobox_type, $parameter);
$this->infobox_external_link = $this->cspm_get_setting('infoboxsettings', 'infobox_external_link', 'same_window');
$target = ($this->infobox_external_link == 'new_window') ? ' target="_blank"' : '';
$the_post_link = ($this->infobox_external_link == 'disable') ? $item_title : '<a href="'.$the_permalink.'" title="'.$item_title.'"'.$target.'>'.$item_title.'</a>';
$output = '';
$output .= '<div class="cspm_infobox_content_container '.$status.' infobox_'.$map_id.' '.$infobox_type.'" data-map-id="'.$map_id.'" data-post-id="'.$post_id.'" data-show-carousel="'.$carousel.'">';
if($infobox_type == 'square_bubble' || $infobox_type == 'rounded_bubble'){
$output .= '<div class="cspm_infobox_img">';
$output .= ($this->infobox_external_link != 'disable') ? '<a href="'.$the_permalink.'" title="'.$item_title.'"'.$target.'>'.$post_thumbnail.'</a>' : $post_thumbnail;
$output .= '</div>';
$output .= '<div class="cspm_arrow_down '.$infobox_type.'"></div>';
}elseif($infobox_type == 'cspm_type1'){
$output .= '<div class="cspm_infobox_img">'.$post_thumbnail.'</div>';
$output .= '<div class="cspm_infobox_content">';
$output .= '<div class="title">'.$the_post_link.'</div>';
$output .= '<div class="description">'.$item_description.'</div>';
$output .= '</div>';
$output .= '<div style="clear:both"></div>';
$output .= '<div class="cspm_arrow_down"></div>';
}elseif($infobox_type == 'cspm_type2'){
$output .= '<div class="cspm_infobox_img">'.$post_thumbnail.'</div>';
$output .= '<div class="cspm_infobox_content">';
$output .= '<div class="title">'.$the_post_link.'</div>';
$output .= '</div>';
$output .= '<div class="cspm_arrow_down"></div>';
}elseif($infobox_type == 'cspm_type3'){
$output .= '<div class="cspm_infobox_img">'.$post_thumbnail.'</div>';
$output .= '<div class="cspm_infobox_content">';
$output .= '<div class="title">'.$the_post_link.'</div>';
$output .= '</div>';
$output .= '<div class="cspm_arrow_down"></div>';
}elseif($infobox_type == 'cspm_type4'){
$output .= '<div class="cspm_infobox_content">';
$output .= '<div class="title">'.$the_post_link.'</div>';
$output .= '</div>';
$output .= '<div class="cspm_arrow_down"></div>';
/**
* @since 2.7 */
}elseif($infobox_type == 'cspm_type5'){
$output .= '<div class="cspm_infobox_content">';
$output .= '<div>';
$output .= '<div class="cspm_infobox_img">'.$post_thumbnail.'</div>';
$output .= '<div class="title">'.$the_post_link.'</div>';
$output .= '<div class="telnr"><a class="wm-button color-read" href="tel:'.$telnr.'"><img src="http://porosija.com/pinfo/wp-content/uploads/2015/06/Phone-18-18-dimenzionet.png" height="18" width="18"></a>';
$output .= '<a class="wm-button color-read telnr1" style="left: 10px;" href="tel:'.$telnr1.'"><img src="http://porosija.com/pinfo/wp-content/uploads/2015/06/Phone-18-18-dimenzionet.png" height="18" width="18"></a>';
$output .= '<a class="wm-button color-blue email" style="left: 20px;" href="mailto:'.$email.'?Subject=Un%20jam%20informuar%20për%20ju%20nga%20www.porosija.com "><img src="http://porosija.com/pinfo/wp-content/uploads/2015/06/email-ico.png" height="18" width="18"></a></div>';
答案 0 :(得分:0)
我不确定我理解你的问题。如果你想隐藏服务器上的一个按钮(例如,通过使用php),我想你需要从客户端收到某种反馈,例如提交表单,检查后,如果某个变量是空的,那么就做不生成用于显示按钮的html代码。现在,另一种可能性是使用Javascript隐藏按钮;在这种情况下,您需要将事件绑定到某个字段(例如),当用户在其中写入内容时,您将显示该按钮。
第一个案例:
PHP:
$myvar = $_GET['myvar_from_form'];
$html = '...';
if(isset($myvvar)){
$html = '<button>...</button>';
}
第二个案例:
HTML:
<input type="text" name="myvar" />
<button style="display: none;">Button</button>
JavaScript的:
var input = document.querySelector('input');
input.addEventListener('input', function(){
document.querySelector('button').style.display = '';
console.log('input changed to: ', input.value);
});
您可能还想验证新输入的值何时为空。