Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript onkeyup不处理隐藏()_Javascript_Jquery - Fatal编程技术网

Javascript onkeyup不处理隐藏()

Javascript onkeyup不处理隐藏(),javascript,jquery,Javascript,Jquery,我试图根据用户的输入显示和隐藏div内容 这是我的密码: <input type="text" name="pass" id="pass" onkeyup="check_input(this.value)"> <div id="repeated_pattern" style="display:none"> <b>REPEATED PATTERN</b> <p>Repeated characters</p>

我试图根据用户的输入显示和隐藏div内容

这是我的密码:

<input type="text" name="pass" id="pass" onkeyup="check_input(this.value)">

<div id="repeated_pattern" style="display:none">
    <b>REPEATED PATTERN</b>
    <p>Repeated characters</p>
</div>

<script>
function check_input(value){
     //this would check if there are 3 or more characters repeated consecutively
     var repeat_pattern = /(.)\1\1/.test(value);  

     if(repeat_pattern)  { 
        $("#repeated_pattern").show(500); 
     }else{ 
        $("#repeated_pattern").hide(500); 
     }
}    
</script>

重复模式
重复字符

功能检查输入(值){ //这将检查是否有3个或更多字符连续重复 var repeat_pattern=/()\1\1/.test(值); 如果(重复_模式){ $(“#重复#模式”)。显示(500); }否则{ $(“#重复#模式”)。隐藏(500); } }
测试:

  • 当我尝试输入
    gg
    时,div内容没有显示,因此结果正常
  • 当我尝试输入
    ggg
    时,div内容会显示出来,因此结果正常
  • 但是当我试图删除一个
    g
    时,它现在是
    gg
    。应该是div的内容必须隐藏,但仍然显示
    onkeyup
    无法使用
    hide()
    功能正常工作
    如何使用hide()或反之亦然?

    我遇到了以下错误:

    ReferenceError: check_input is not defined
    
    尝试在Javascript中设置事件处理程序,使其在范围内:

    Javascript:

    // Event handlers
    if(document.addEventListener)
    document.getElementById('pass').addEventListener('keyup',check_input,false);
    // Good old Internet Explorer event handling code
    if(document.attachEvent)
    document.getElementById('pass').attachEvent('keyup',check_input);
    
    function check_input() {
        var value = $(this).val();
        //this would check if there are 3 or more characters repeated consecutively
        var repeat_pattern = /(.)\1\1/.test(value);
    
        if (repeat_pattern) {
            $("#repeated_pattern").show(500);
        } else {
            $("#repeated_pattern").hide(500);
        }
    }
    
    HTML:

    我试图根据用户的输入显示和隐藏div内容。这是我的密码:
    重复模式
    重复字符


    使用哪种浏览器Firefox,等等,我将在我的Chromenah中试用,它实际上不起作用。我将输出放在一个模态对话框中。所以,当我输入字符时,我单击按钮,然后看到结果它在firefox和chrome中运行良好
    I'm trying to show and hide div contents depends on the input of the user. Here are my codes:
    <input type="text" name="pass" id="pass">
    <div id="repeated_pattern" style="display:none"> <b>REPEATED PATTERN</b>
    
        <p>Repeated characters</p>
    </div>