在使用jQuery的.keydown()之后如何对元素进行永久更改? [英] How to make a permanent change to an element after using jQuery's .keydown()?

查看:106
本文介绍了在使用jQuery的.keydown()之后如何对元素进行永久更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下jQuery代码:

I have the following jQuery code:

function showResult(str)
{
if (str.length == 0)
{
    $('#mySearch').html('');
    return;
}
else
{
    $('#mySearch').load('search/'+str,function(){
        $('#mySearch').css({
            'background-color': 'white',
            'width': '250px',
            'position': 'absolute',
            'right': '0'
        })
    });
}

$(document).click(function(event) {
if ( !$(event.target).hasClass('mySearch'))
{
     $('#mySearch').html('');
     $('#main_search').val('');
}
});

$(document).keydown(function(e){
    if (e.keyCode == 40) { 
       $('#mySearch tr.myRow:first').addClass("a_classy_class");
       return false;
    }
});
}

当我按下向下键时,类'a_classy_class'被添加到ID为'myRow'的标签中.但是,一旦我停止按下向下箭头键,该类就会被删除.我如何使更改永久生效,以便在我停止按向下箭头键后更改仍然有效?

When I press the down arrow key the class 'a_classy_class' is added to the tag with id 'myRow'. However, as soon as I stop pressing the down arrow key the class is removed. How do I make the change permanent, so that after I stop pressing the down arrow key the change holds?

推荐答案

除了其他建议以外,如果重新加载页面,更改将不会继续.

In addition to the other suggestions, if the page is reloaded, your changes will not persist.

这篇关于在使用jQuery的.keydown()之后如何对元素进行永久更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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