简体   繁体   English

Javascript文本框按键事件

[英]Javascript textbox keydown event

I have two textboxes, and when I write something, I want to change the color of p which is in another div if two textboxes have the same value. 我有两个文本框,当我写东西时,如果两个文本框具有相同的值,我想更改另一个div中p的颜色。

So far I have written this, but it's not working: 到目前为止,我已经写了这个,但是没有用:

<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>

I have use jQuery for your solution. 我已经使用jQuery作为您的解决方案。 If you are interested on it then please Try this: 如果您对此感兴趣,请尝试以下操作:
HTML: 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: 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: CSS:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM