Php yii2框架:帮助。它仅适用于Gridview的第一页
我使用Jquery在鼠标悬停在文本上时显示工具提示。它在每一页上都能正常工作 我的gridview中还有一个图像列。 我使用Jquery在鼠标悬停在图像上时放大这些图像 但问题是,它只在第一页起作用 我读了一些文章,建议在JS脚本中使用选择器,但我不知道如何实现它 请帮帮我 非常感谢,很抱歉打扰大家 这是我的查看代码Php yii2框架:帮助。它仅适用于Gridview的第一页,php,gridview,pagination,yii2,jquery-hover,Php,Gridview,Pagination,Yii2,Jquery Hover,我使用Jquery在鼠标悬停在文本上时显示工具提示。它在每一页上都能正常工作 我的gridview中还有一个图像列。 我使用Jquery在鼠标悬停在图像上时放大这些图像 但问题是,它只在第一页起作用 我读了一些文章,建议在JS脚本中使用选择器,但我不知道如何实现它 请帮帮我 非常感谢,很抱歉打扰大家 这是我的查看代码 尝试以这种方式注册Js use yii\web\View; 然后您的javascript代码实现如下 <?php $this->registerJs(" $('
尝试以这种方式注册Js
use yii\web\View;
然后您的javascript代码实现如下
<?php
$this->registerJs("
$('body').tooltip({selector: '[data-toggle="tooltip"]'});
$('.enlargephoto').hover(function(){
$('.photobox').remove();
var srcval = $(this).attr('src');
var names = $(this).attr('namas');
$('<div class=\'photobox\' ></div>')
.html('<p class=\'names\'>'+names+'</p><img src='+srcval+'></img>')
.appendTo('#usergrids').hide().fadeIn('fast');
},function(){
$('.photobox').remove();
});
$('.enlargephoto').mousemove(function(e){
var xx = e.pageX - 20;
var tt = e.pageY - 120;
$('.photobox').css({top:tt, left:xx});
});
", View::POS_END);
您可能正在使用Ajax GridView。在代码中,事件“hover”的侦听器仅添加到页面加载时已经存在的元素中。你需要
$('body').on('mouseenter','enlargephoto',function(){
$('.photobox').remove();
var srcval=$(this.attr('src');
变量名称=$(this.attr('namas');
$('')
.html(''+names+'
')
.appendTo('#usergrids').hide().fadeIn('fast');
});
$('body').on('mouseleave','.enlargephoto',function(){
$('.photobox').remove();
});
$('body').on('mousemove','.enlargephoto'函数(e){
var xx=e.pageX-20;
var tt=e.pageY-120;
$('.photobox').css({top:tt,left:xx});
});
悬停事件已经不存在了,所以我在真实事件中破坏了它。仍然只在第一页
$('body').on('mouseenter', '.enlargephoto', function(){
$('.photobox').remove();
var srcval = $(this).attr('src');
var names = $(this).attr('namas');
$('<div class=\'photobox\' ></div>')
.html('<p class=\'names\'>'+names+'</p><img src='+srcval+'></img>')
.appendTo('#usergrids').hide().fadeIn('fast');
});
$('body').on('mouseleave', '.enlargephoto' ,function(){
$('.photobox').remove();
});
$('body').on('mousemove', '.enlargephoto' function(e){
var xx = e.pageX - 20;
var tt = e.pageY - 120;
$('.photobox').css({top:tt, left:xx});
});