在jQuery中强制一个事件 [英] Force an event in jQuery

查看:80
本文介绍了在jQuery中强制一个事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

To all;

我已经为小数位创建了一个向上和向下计数器,当发生更改时,我强制一个模糊事件重新计算具有以下内容的字段代码:

I have created a up and down counter for decimal places and when a change occurs I have it force a blur event to recalculate fields with the following code:

$('button').click(function(){       
    var decPlaces = document.calculator.dpv.value * 1;
    var hii = document.calculator.origin.value;
    if (this.id == 'up' && decPlaces < 9){                    
        document.calculator.dpv.value  =  decPlaces + 1;
        if (hii != ''){
            document.calculator[hii].focus();
            document.calculator[hii].blur();
        }
    }
    if (this.id == 'down' && decPlaces > 0){    
        document.calculator.dpv.value  =  decPlaces - 1;
        if (hii != ''){
            document.calculator[hii].focus();
            document.calculator[hii].blur();
        }
    } 

Wo在FF中很好,但在其他方面特别是IE - 对更清洁和更快速度的建议表示赞赏。

Works well in FF but drags in others particularly IE - suggestions on making the cleaner and faster is appreciated.

Bob

推荐答案

触发/强制发生事件的官方jquery方法是

The official jquery way to trigger/force an event is

$("selector").trigger("blur");
$("selector").trigger("focus");

但我不知道这可以帮助你。

But I'm not sure this is what will help you.

这篇关于在jQuery中强制一个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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