如何将代码从使用.hover()更改为使用.click()和.hover()

时间:2013-09-11 20:12:15

标签: javascript jquery

如何将此脚本从悬停到onclick并悬停:

$j = jQuery.noConflict();
$j(document).ready(function () {
    $j(".swatch-anchor").hover(function () {
        var newTitle = $j(this).attr("title");
        $j("#colour-name").html(newTitle);
    },
    function () {
        var swapTitle = $j("#colour-name").html();
        $j(this).attr("title", swapTitle);
        $j("#colour-name").html("");
    });
});

2 个答案:

答案 0 :(得分:1)

试试这个:

$j = jQuery.noConflict();
$j(document).ready(function () {
    $j(".swatch-anchor").on('click mouseenter',function () {
        var newTitle = $j(this).attr("title");
        $j("#colour-name").html(newTitle);
    });

    $j(".swatch-anchor").on('mouseleave',function () {
        var swapTitle = $j("select-option.selected a").text();
        $j("#colour-name").html("");
    });
});

答案 1 :(得分:0)

解决:

http://jsfiddle.net/4cPQG/

$j(".swatch-anchor")
.on('mousedown mouseover', function () {
    //...
})
.on('mouseup mouseout', function () {
    //...
});