admin管理员组文章数量:1343374
<input type="text" value="Text box"/>
<input type="button" onclick="toggle();"/>
How do I make the text box disappear and reappear with JavaScript?
<input type="text" value="Text box"/>
<input type="button" onclick="toggle();"/>
How do I make the text box disappear and reappear with JavaScript?
Share Improve this question edited Jun 10, 2010 at 2:13 Gert Grenander 17.1k6 gold badges41 silver badges43 bronze badges asked Jun 10, 2010 at 2:11 Anonymous the GreatAnonymous the Great 1,6695 gold badges15 silver badges18 bronze badges3 Answers
Reset to default 4JavaScript:
function toggle() {
var element=document.getElementById('element1');
if ( element.style.display!='none' ) {
element.style.display='none';
} else {
element.style.display='';
}
}
HTML:
<input id="element1" type="text" value="Text box"/>
<input type="button" onclick="toggle();"/>
put this code on page:
<script>
function toogle(id) {
if (document.getElementById(id).style.visibility = 'hidden') {
document.getElementById(id).style.visibility = 'visible';
} else {
document.getElementById(id).style.visibility = 'hidden'
}
}
</script>
Now, just give a "id" element to your input tag, and pass this 'id' to the call of the javascript function on your button. Something like:
<input id="element1" type="text" value="Text box"/>
<input type="button" onclick="toggle('element1');"/>
JQuery provides some nice built-in functionality for this:
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
function toggle() {
$('#element1').toggle();
}
</script>
本文标签: How do I make a quotinput type textquot go invisible with JavaScriptStack Overflow
版权声明:本文标题:How do I make a "input type text" go invisible with JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743706542a2525214.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论