簡體   English   中英

單擊事件后如何調用javascript鼠標懸停功能?

[英]how call the javascript mouse over function after click event?

在要調用首次單擊事件的函數下方,當用戶單擊時,該函數將在鼠標懸停時調用?

<a href="javascript:void(0);" id="digit<?php echo $k;?>" onClick="javascript:return swapClass('<?php echo strtoupper($v);?>','<?php echo $k;?>');" class="GetDivCount" rel="<?php echo $k;?>" onMouseMove="javascript:return swapClass('<?php echo strtoupper($v);?>','<?php echo $k;?>');"> 

--

function swapClass(getId,keyId) {

<!-- INACTIVE ACTIVE CLASS IF SELECT ALL BUTTONS -->
if(jQuery('.digit_active').length==15)
{
    var p=0;
    jQuery('.digit_active').each(function(){
        var CurrentActive=$(this);
        var activeValue = CurrentActive.attr('rel');
        jQuery('#digit'+activeValue).removeClass('digit_active');
        p++;
    });
    arrString.length=0;
    jQuery("#middleReload").load(location.href + " #middleReload>*","");
}
<!-- INACTIVE ACTIVE CLASS IF SELECT ALL BUTTONS -->

jQuery('#digit'+keyId).addClass('digit_active');


/*
|-------------------------------|           
|   GROUP A FOR RED POINTS  |                                               
|               |
|-------------------------------|
*/
if($('#colorDiv'+keyId).hasClass('red_Q')){
    // FOR GET LETTER HERE
    var BonusRed=getId;


}


arrString.push(getId);
var wordFind;
jQuery.ajax({
url:'ajax.php?action=wordFind&word='+arrString,
    cache:false,
    async:false,
    type:"GET",
    success:function(res){
        console.log(res);//To check you are getting any reponse
        if(res=="find")
        {
            <!--BUTTON SOUND -->
            playAudio();
            <!--BUTTON SOUND -->

            jQuery("#wordReload").load(location.href + " #wordReload>*","");

            arrString.length=0;

            document.getElementById('bonusDiv'+keyId).style.display='block';
            jQuery('#bonusDiv'+keyId).animate({
            bottom: 200, opacity: 1
            }, 300 );

            jQuery('#bonusDiv'+keyId).fadeOut('slow');

            <!--REMOVE SELECTED ACTIVE CLASS START -->
            jQuery('#digit'+keyId).removeClass('digit_active');
            var m=0;
            var active=new Array();
            jQuery('.digit_active').each(function(){
                var CurrentActive=jQuery(this);
                var activeValue = CurrentActive.attr('rel');
                jQuery('#digit'+activeValue).removeClass('digit_active');
                m++;
                });
            <!--REMOVE SELECTED ACTIVE CLASS END -->
        }
    }

});
}

您可以使用觸發功能觸發鼠標懸停

 jQuery(selector).trigger('mouseover');

回答

您可以使用.trigger()方法以編程方式從另一個函數初始化鼠標懸停事件。

例:

function swapClass(getId,keyId) {
  // .. code

  // Invoke the mouseover event
  $('.other-html-element').trigger('mouseover');
}

請注意

請注意,在元素上分配onclick事件(如您所做的那樣)不是一種好習慣:

<a href="" class="GetDivCount" onclick="javascript: return swapClass();">Click me</a>

相反,您最好綁定到這樣的元素:

$(function(){

    $('.GetDivCount').click(function(){ swapClass(); });

});

演示版

另請參閱此演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM