Jquery按键更改CSS [英] Jquery keypress change CSS

查看:54
本文介绍了Jquery按键更改CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,





为什么工作正常:

 jQuery(document).bind('keydown',function(evt){
if(evt.keyCode == 38){
var element = document.getElementById(table_row_2);
element.style.backgroundColor =red;
}
});



但这不起作用:

 jQuery(document).bind('keydown',function(evt){
if(evt.keyCode == 38){
var element = document.getElementById( table_row_2);
element.css(background-color,red);
}
});





我尝试了什么:



虽然这样做再次正常:

< pre lang =   text> $(< span class =code-sdkkeyword> document )。ready( function (){
$( tr)。hover(函数(){
$( this )。css( background-color red);
}, function (){
$( this )。css(< span class =code-string> background-color 红色);
});
});





我很困惑......

解决方案

< blockquote>( document )。ready( function (){


tr)。hover( function (){


this )。css( background-color red);
}, function (){


Hello,


Why is this working just fine:

jQuery(document).bind('keydown', function (evt) {
        if (evt.keyCode == 38) {
            var element = document.getElementById("table_row_2");
            element.style.backgroundColor = "red";
        }
    });


But this isn't working:

jQuery(document).bind('keydown', function (evt) {
        if (evt.keyCode == 38) {
            var element = document.getElementById("table_row_2");
            element.css("background-color","red");
        }
    });



What I have tried:

while this again works just fine:

<pre lang="text">$(document).ready(function () {
        $("tr").hover(function () {
            $(this).css("background-color", "red");
        }, function () {
            $(this).css("background-color", "red");
        });
    });



Im confused...

解决方案

(document).ready(function () {


("tr").hover(function () {


(this).css("background-color", "red"); }, function () {


这篇关于Jquery按键更改CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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