<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>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743706542a4493466.html
评论列表(0条)