当输入具有指定值时隐藏div [英] Hide div when input has an assigned value
本文介绍了当输入具有指定值时隐藏div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当值= 10时我试图隐藏div
I'm trying to hide a div when the value = 10
这是代码,演示可以正常工作:
Here is the code and demo working fine:
<script>
$('input[name=test]').keyup(function(){
if($(this).val()<10)
$('#yeah').show();
else
$('#yeah').hide();
});
</script>
<label>Type whatever</label>
<input type="text" name="test"value="10" />
<div id="yeah" style="display:none;">
<input type="submit" />
</div>
但是我正在尝试将该代码转换为原型代码,并且尝试了此代码 :
But I'm trying to convert that code into Prototype code and I tried this code:
Event.observe(window, 'load', function () {
$('input[name=test]').keyup(function(){
if($(this).val()<10)
$('#yeah').show();
else
$('#yeah').hide();
});
});
我只想在原型代码中输入值= 10时隐藏div.
I only want to hide the div when input value = 10 into prototype code.
请有人可以帮助我吗?
推荐答案
为文本框提供ID
.例如:
<input type="text" id="txtbox" name="test" value="10" />
更改:
<div id="yeah" style="display:inline;">
收件人:
<div id="yeah" style="display:none;">
Event.observe('txtbox', 'keyup', function () {
if ($$('input[name="test"]')[0].value < 10){
$$('#yeah')[0].show();
}
else{
$$('#yeah')[0].hide();
}
});
注意:您也可以使用.first()
代替[0]
Note: You could also use .first()
instead of [0]
这篇关于当输入具有指定值时隐藏div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文