在没有document.ready()的情况下悬停不工作? [英] hover not working without document.ready()?

查看:68
本文介绍了在没有document.ready()的情况下悬停不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 $(document).ready(function(){
$('。simpleTooltip')。hover(function(){
var hrefval = $(this)。 attr('href');
hrefval = hrefval.replace('#','');
var title = $('a [name ='+ hrefval +']')。 parent()。parent()。text(); //$(this).attr('title');
if(title.length> 200)
{
title = title.substring(0,200);
title = title +...........
}
$(this).data('tipText',title) .removeAttr('title');
$('< p class =tooltip>< / p>')
.text(title)
.appendTo('body ')
.fadeIn('slow');
},function(){
$(this).attr('title',$(this).data('tipText') );
$('。tooltip')。remove();
})。mousemove(function(e){
var mousex = e.pageX + 20;
var mousey = e.pageY + 20;
$('。tooltip')
.css({top:mousey,left:mousex})
});
});





上述脚本在没有document.ready()的情况下无效。我有一个文档的一部分通过ajax加载,因此包含对上述脚本的引用的页面不会重新加载,因为页面没有加载。

所以我该如何使它工作? div class =h2_lin>解决方案

(document).ready(function(){


('。simpleTooltip')。hover(function(){
var hrefval =


(this).attr('href');
hrefval = hrefval.replace('#','');
var title =


$(document).ready(function() {
    $('.simpleTooltip').hover(function(){
		var hrefval= $(this).attr('href');
		hrefval=hrefval.replace('#','');
        var title =$('a[name="' + hrefval + '"]').parent().parent().text(); //$(this).attr('title');
		if (title.length > 200)
			{
			title = title.substring(0,200);
			title = title + "..........."
			}
        $(this).data('tipText', title).removeAttr('title');
        $('<p class="tooltip"></p>')
        .text(title)
        .appendTo('body')
        .fadeIn('slow');
    }, function() {
        $(this).attr('title', $(this).data('tipText'));
        $('.tooltip').remove();
    }).mousemove(function(e) {
        var mousex = e.pageX + 20;
        var mousey = e.pageY + 20;
        $('.tooltip')
        .css({ top: mousey, left: mousex })
    });
});



the above script is not working without document.ready(). I have a part of the document which is loaded via ajax and hence the page which contains reference to the above script does not reload as the page is not loading.
so how can I make it work?

解决方案

(document).ready(function() {


('.simpleTooltip').hover(function(){ var hrefval=


(this).attr('href'); hrefval=hrefval.replace('#',''); var title =


这篇关于在没有document.ready()的情况下悬停不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆