Javascript 文本框按键事件

Javascript textbox keydown event

我有两个文本框,当我写东西时,如果两个文本框具有相同的值,我想更改另一个 div 中 p 的颜色。

到目前为止我已经写了这个,但它不起作用:

<input id="sifre_text" type="text" />
<input id="sifre_tekrar_text" type="text" 
onkeydown="if(document.getElementById('sifre_tekrar_text').value
== if(document.getElementById('sifre_text').value')){
var c=document.getElementById('sifre_check').childNodes;    
c[1].style.backgroundColor = 'yellow';}"/> 
<div id="sifre_check">
<p style="width:450px,height:350px"></p>
</div>

我已将 jQuery 用于您的解决方案。如果您对此感兴趣,请 试试这个:
HTML:

<input class="input-value" id="sifre_text" type="text" />
<input class="input-value" id="sifre_tekrar_text" type="text"/> 

<div id="sifre_check">
</div>

jQuery:

$(function(){
    $(".input-value").on("change", function(){
        var a = $("#sifre_text").val();
        var b = $("#sifre_tekrar_text").val();
        if(a == b)
            $("#sifre_check").css("background-color", "yellow");     
    });
})

CSS:

#sifre_check {
    background-color: red; 
    width:450px; 
    height:350px
}