简体   繁体   中英

how call the javascript mouse over function after click event?

Below the function I want to call first click event and as user click then the function will call on mouse over is it possible?

<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');

Answer

You can use the .trigger() method to initialize a mouseover event programmatically from another function.

Example:

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

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

Please note

Please note that assigning the onclick event on the element (as you are doing) is not good practice:

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

Instead you would be better off binding to the element like this:

$(function(){

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

});

Demo

Also see this demo .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM