Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jquery中获取当前悬停锚的值_Jquery - Fatal编程技术网

如何在jquery中获取当前悬停锚的值

如何在jquery中获取当前悬停锚的值,jquery,Jquery,我试图在这里获得鼠标悬停的当前链接的值: <script type='text/javascript' src='jq.js'></script> <script type='text/javascript'> $(function(){ $('a').hover(function(){ var imgName= $('a[href^=num]').val(); alert(imgName); }

我试图在这里获得鼠标悬停的当前链接的值:

    <script type='text/javascript' src='jq.js'></script>
    <script type='text/javascript'>

    $(function(){


    $('a').hover(function(){
    var imgName= $('a[href^=num]').val();
    alert(imgName);

    });




    });

$(函数(){
$('a')。悬停(函数(){
var imgName=$('a[href^=num]')。val();
警报(imgName);
});
});
为了实现这一点,我需要在这里做些什么

    </script>
    </head>
    <body>

    <a href='numone'>numone</a>
    <a   href='numtwo'>numtwo</a>

试试这个:

<script type='text/javascript' src='jq.js'></script>
<script type='text/javascript'>

    $(
        function()
        {
            $('a').hover
            (
                function()
                {
                    var imgName= $(this).attr("href");
                    alert(imgName);
                }
            );
    }
);
</script>

$(
函数()
{
$('a')。悬停
(
函数()
{
var imgName=$(this.attr(“href”);
警报(imgName);
}
);
}
);
试试这个:

<script type='text/javascript' src='jq.js'></script>
<script type='text/javascript'>

    $(
        function()
        {
            $('a').hover
            (
                function()
                {
                    var imgName= $(this).attr("href");
                    alert(imgName);
                }
            );
    }
);
</script>

$(
函数()
{
$('a')。悬停
(
函数()
{
var imgName=$(this.attr(“href”);
警报(imgName);
}
);
}
);

尝试

尝试

如果您只想在鼠标进入元素时获得它:

$(function(){

    $('a').mouseenter(function(){

        // Here, `this` points to the DOM element for
        // the anchor.

        // jQuery helps you get its contents, either as HTML:
        alert($(this).html());
        // Or text:
        alert($(this).text());

        // Or if you just want its href, id, etc., you can
        // just get that directly without a jQuery wrapper:
        alert(this.href);
        alert(this.id);
        alert(this.className);
    });

});
(我将其切换到了
mouseenter
,因为您没有使用的下半部分,即
mouseleave

jQuery文档中的更多内容:


如果您只想在鼠标进入元素时获取它:

$(function(){

    $('a').mouseenter(function(){

        // Here, `this` points to the DOM element for
        // the anchor.

        // jQuery helps you get its contents, either as HTML:
        alert($(this).html());
        // Or text:
        alert($(this).text());

        // Or if you just want its href, id, etc., you can
        // just get that directly without a jQuery wrapper:
        alert(this.href);
        alert(this.id);
        alert(this.className);
    });

});
(我将其切换到了
mouseenter
,因为您没有使用的下半部分,即
mouseleave

jQuery文档中的更多内容:


编辑了该函数。请立即检查该功能。请现在检查可能的重复可能的重复