在PHP中动态更改悬停时另一个元素的内容

时间:2017-04-06 04:34:40

标签: php jquery html css hover

我知道那里有答案显示如何使用java script / jquery等静态地实现标题行为。当我不总是拥有元素的确切ID时,问题就出现了。因为,我从帖子中动态制作一个表格(来自wordpress的帖子,但这个问题并没有解决任何插件或wordpress相关的查询无论如何,我自己做了这个小小的演出,除了帖子本身之外没有一些特别的插件帮助。

所以我现在做的是This. 我创建了一个表,并使用html n php调用表列,同时从帖子中提取数据。

我想要做的是,每当我将鼠标悬停在视图详细信息上时,所有者姓名和所有者联系人都应该更改我拥有的其他字符串的值。

现在,我的问题是我无法为每个元素赋予唯一ID,因此我无法使用基于正常身份的jquery并设置悬停操作来完成任务。我想到了使用css选择器(+,〜,>等)但我无法使用样式的内容属性更改内容。因此,如果存在此问题的任何最佳解决方案,那将非常有用。 在此先感谢&问候。

我的代码(如果需要的话) -



<?php
$string = get_post_meta( $post->ID,'property_owner_name',true);
 $tring = get_post_meta( $post->ID,'property_owner_alternate_contact',true);
 $fring=substr($tring, 0, -5)."XXXXXXXXXX"; 

 $owner_name;
 $owner_contact;
 if((current_user_can('editor')||current_user_can('administrator')))
$owner_name = 	 $string;
else
$owner_name ='XXXXXX'; // String to change to
	
	 if((current_user_can('editor')||current_user_can('administrator')))
$owner_contact = 	 $fring;
else
$owner_contact =substr($fring,0,10);  //String to change to
 
?>


 
<tr>
    
<td class="text-left"><?php echo inspiry_get_property_location( $post->ID );   ?></td>
<td class="text-left"><?php echo inspiry_get_property_status( $post->ID );   ?></td>

<td class="text-left hide2"><?php echo inspiry_get_property_types( $post->ID ); ?></td>

<td class="text-left hide1"><?php the_title(); ?></td>

<td class="text-left hide3" id="a">XXXXXX</td>

<td class="text-left hide3" id="b"> XXXXXXXXXX</td>

<td class="text-right"><a href="<?php the_permalink(); ?>" class="btn real-btn"style="background:#68cfef; color:#fff; min-width:115px;" >VIEW DETAILS</a></td>

</tr>
  
								
&#13;
&#13;
&#13;

更新(在循环中实际调用此模板的文件代码):

&#13;
&#13;
<div id="home-properties" class="property-items-container clearfix">
                                    <?php
                                    /* List of Properties on Homepage */
                                    $number_of_properties = intval( get_option('theme_properties_on_home') );
                                    if(!$number_of_properties){
                                        $number_of_properties = 4;
                                    }

                                    if ( is_front_page()  ) {
                                        $paged = (get_query_var('page')) ? get_query_var('page') : 1;
                                    }

                                    $home_args = array(
                                        'post_type' => 'property',
                                        'posts_per_page' => $number_of_properties,
                                        'paged' => $paged
                                    );

                                    /* Modify home query arguments based on theme options - related filters resides in functions.php */
                                    $home_args = apply_filters( 'real_homes_homepage_properties', $home_args );

                                    /* Sort Properties Based on Theme Option Selection */
                                    $sorty_by = get_option('theme_sorty_by');
                                    if ( ! empty( $sorty_by ) ) {
                                        if ( $sorty_by == 'low-to-high' ) {
                                            $home_args[ 'orderby' ]  = 'meta_value_num';
                                            $home_args[ 'meta_key' ] = 'REAL_HOMES_property_price';
                                            $home_args[ 'order' ]    = 'ASC';
                                        } elseif ( $sorty_by == 'high-to-low' ) {
                                            $home_args[ 'orderby' ]  = 'meta_value_num';
                                            $home_args[ 'meta_key' ] = 'REAL_HOMES_property_price';
                                            $home_args[ 'order' ]    = 'DESC';
                                        } elseif ( $sorty_by == 'random' ) {
                                            $home_args[ 'orderby' ] = 'rand';
                                        }
                                    }
                                    $home_properties_query = new WP_Query( $home_args );

                                    /* Homepage Properties Loop */
                                    if ( $home_properties_query->have_posts() ) :

                                        $post_count = 0;?>
											
										<table  width=100% id="design2" class="table-fill" border=0>
										
										<tr>
										<th class="text-center">Location</th>
										<th class="text-center">Status</th>
										<th class="text-center hide2">Type</th>
										<th class="text-center hide1">Description</th>
										<th class="text-center hide3">Owner's Name</th>
										<th class="text-center hide3">Owner's Number</th>
										<th class="text-center"></th>
										</tr>
										<tbody class="table-hover">
										<?php
                                        while ( $home_properties_query->have_posts() ) :

                                            $home_properties_query->the_post();

                                            /* Display Property for Home Page */
                                            get_template_part('template-parts/property-for-home');

                                            /* To output clearfix after every 2 properties */
                                            $post_count++;                                       
                                                /*echo '<div class="clearfix"></div>';*/
                                          
											?>
											<?php

                                        endwhile;
										echo '<tbody></table>';

                                    else:
                                        ?>
                                        <div class="alert-wrapper">
                                            <h4><?php _e('No Properties Found!', 'framework') ?></h4>
                                        </div>
                                        <?php
                                    endif;
                                    ?>

                                </div>
&#13;
&#13;
&#13;

是的,我买了一个主题,他们显然支持定制。实际上我已经尝试过使用jquery给我的列需要一个基于 $ post_count 更改的ID,例如&#39; a1&#39; &#39; A2&#39; &#39; a3&#39;,&#39; b1&#39; &#39; B2&#39; &#39; B3&#39;等等,但我真的不知道我在jquery中把它搞砸了(我把一些例子从stackoverflow中删入了我的代码),把它们放在循环模板中,而控制台给了我一些&#39; uncaughtreferenceerrors&#39; &安培;下一次的其他一些事情(java n的新东西)(总的来说,我无法正确地破解它)。所以,如果你真的想出一些我可以使用的东西,那就非常有帮助......如果由css,js或者wtevr完成它并不重要。 在此先感谢

1 个答案:

答案 0 :(得分:0)

使用Post id作为唯一元素完成它并且遇到问题因为wordpress在js中没有使用'$',而是使用'jquery'术语来做工作。谢谢fr看看问题。这是我的编辑模板代码,如果以后需要的话。

<?php
$string = get_post_meta( $post->ID,'inspiry_property_owner_name',true);
 $tring = get_post_meta( $post->ID,'inspiry_property_owner_alternate_contact',true);
 $fring=substr($tring, 0, -5)."XXXXXXXXXX"; 

 $owner_name;
 $owner_contact;
 if((current_user_can('editor')||current_user_can('administrator')))
$owner_name = 	 $string;
else
$owner_name ='XXXXXX';
	
	 if((current_user_can('editor')||current_user_can('administrator')))
$owner_contact = 	 $fring;
else
$owner_contact =substr($fring,0,10);
 

  $id = get_the_ID();
 $uniqueid = 'infohide'.$id;
 $uniqueidz = 'infounhide'.$id; 
  
 ?>
 
 <style>
.<?php echo $uniqueidz; ?>{
	display:none;
}
</style>

    <tr>
<td class="text-left"><?php echo inspiry_get_property_location( $post->ID );   ?></td>
<td class="text-left"><?php echo inspiry_get_property_status( $post->ID );   ?></td>
<td class="text-left hide2"><?php echo inspiry_get_property_types( $post->ID ); ?></td>
<td class="text-left hide1"><?php the_title(); ?></td>
  
  
<td class="text-left hide3" >
<div class="<?php echo $uniqueid; ?>">XXXXXX</div>
<div class="<?php echo $uniqueidz; ?>"> <?php echo $owner_name; ?></div>
</td>


<td class="text-left hide3" >
<div class="<?php echo $uniqueid; ?>">XXXXXXXXXX </div>
<div class="<?php echo $uniqueidz; ?>"> <?php echo $owner_contact; ?></div>
</td>


<td class="text-right">

<a href="<?php the_permalink(); ?>" class="btn real-btn"style="background:#68cfef; color:#fff; min-width:115px;" onmouseover="bigImg<?php echo $uniqueid; ?>()" onmouseout="normalImg<?php echo $uniqueid; ?>()">VIEW DETAILS</a>
</td>



<!--td><?php /*$reflFunc = new ReflectionFunction('get_post_meta');
print $reflFunc->getFileName() . ':' . $reflFunc->getStartLine(); */ ?> </td-->
  

  <script>
  function bigImg<?php echo $uniqueid; ?>() {
  jQuery('.<?php echo $uniqueid; ?>').css('display', 'none');
  jQuery('.<?php echo $uniqueidz; ?>').css('display', 'block');
      
}
function normalImg<?php echo $uniqueid; ?>() {
  jQuery('.<?php echo $uniqueidz; ?>').css('display', 'none');
  jQuery('.<?php echo $uniqueid; ?>').css('display', 'block');
}


  
  </script>
								
								
								  </tr>