Javascript onkeyup不处理隐藏()
我试图根据用户的输入显示和隐藏div内容 这是我的密码: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>
<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>