最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using Jquery to hideunhide the textbox if button is clicked - Stack Overflow

programmeradmin4浏览0评论

I have input button , what I want is if a user clicks on the button then textbox should appear.

Below is the code which is not working :

<input type="submit" value="Add Second Driver" id="driver" />
                    <input type="text" id="text" />

$("#driver").click(function() {

    $('#text').show();

  }
 });

Also the textbox should not be visible initially

I have input button , what I want is if a user clicks on the button then textbox should appear.

Below is the code which is not working :

<input type="submit" value="Add Second Driver" id="driver" />
                    <input type="text" id="text" />

$("#driver").click(function() {

    $('#text').show();

  }
 });

Also the textbox should not be visible initially

Share Improve this question edited Jun 29, 2011 at 10:37 Reporter 3,9485 gold badges35 silver badges49 bronze badges asked Jun 29, 2011 at 10:31 Mr AMr A 6,77825 gold badges85 silver badges140 bronze badges
Add a ment  | 

7 Answers 7

Reset to default 3

You can use toggle instead;

$('#text').toggle();

With no parameters, the .toggle() method simply toggles the visibility of elements

try this:

$(document).ready(function(){
    $("#driver").click(function(){
       $("#text").slideToggle("slow");
  });
});

Here's an example using toggle:

http://jsfiddle/x5qYz/

<input type="submit" value="Add Second Driver" id="driver" />
<input type="text" id="text" style="display:none;" />

$("#driver").click(function() {
    $('#text').css('display', 'block');
});
$(function()
{

    // Initially hide the text box
    $("#text").hide();

    $("#driver").click(function()
    {

         $("#text").toggle();
         return false; // We don't want to submit anything here!

    });

});

Try this:

<script type="text/javascript">
jQuery(function ($) {
    $('#driver').click(function (event) {
        event.preventDefault(); // prevent the form from submitting
        $('#text').show();
    });
});
</script>
<input type="submit" value="Add Second Driver" id="driver" />
<input type="text" id="text" />

Make the textbox hidden when the page loads initially like this

Code:

$(document).ready(function () {
$('#text').hidden();
 });

Then your should work the way you want.

发布评论

评论列表(0)

  1. 暂无评论