相关疑难解决方法(0)

如何加速jquery:选择的选择器?

我在一个包含3830个元素的网页中有一个下拉列表.我知道,过分但无论如何.

在jquery中,我使用以下语句获取所选的选项值:

$("#institutionCombo:selected").val();

在找到选择之前有一个明显的暂停.获得该值后,我将其插入页面上的文本框中,因此我知道速度有多快.另外,我在Firebug中使用断点检查了它.

如果我去上学并使用这个javascript:

var div = document.getElementById("maindiv");
var select = div.getElementsByTagName("select")[0];
var ix = select.selectedIndex;
var instId = select.options [ix] .value;

这种速度是瞬间的.

在jquery中是否有某些东西使得:当数字变得过高时,选择的选择器会如此慢?我想在我的脚本中坚持使用jquery,有没有人建议加快在jquery中找到所选的选项?

谢谢,

克雷格

performance jquery selectedindex selected selector

3
推荐指数
1
解决办法
5470
查看次数

在jQuery中使用bind()和each()分配事件处理程序之间的区别?

谁能告诉我使用bind()分配事件处理程序之间的区别:

$(function(){
           $('someElement')
           .bind('mouseover',function(e) {
            $(this).css({
                        //change color
                        });
    })
    .bind('mouseout',function(e) {
        $(this).css({
                    //return to previous state

                 });    
    })
    .bind('click',function(e) {
        $(this).css({
                    //do smth.
                 });    
    })

}); 
Run Code Online (Sandbox Code Playgroud)

并使用each()执行相同的任务:

$('someElement').each(function(){

        $(this).mouseover(function(){$(this).css({/*change color*/})
                    .mouseout(function(){$(this).css({/*return to previous state*/});   
                    });     
                }); 
    });
Run Code Online (Sandbox Code Playgroud)

谢谢.

javascript each jquery bind function

2
推荐指数
1
解决办法
1394
查看次数