javascript 如何在提交按钮单击时调用 <div>

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10257551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 09:11:53  来源:igfitidea点击:

How to call <div> on submit button click

javascriptjqueryhtmlonclick

提问by unkown

  • Please refer code below i m learning jquery and i want to display tag named #childon submit button click using javascript/jquery can any one help me how to call on button click

  • And also want to call #child and #hometag on >>(next button) & <<(prev button)** on button click respectively in code >> and<< is written as &lt and &glt.? can anyone help me out ?

            <div data-role="page" id="home">
                <div data-theme="d" data-role="header">
                    <h3>
                        The Grand Bhagvati
                    </h3>
                    <a data-role="button" data-inline="true" data-direction="reverse" data-transition="slide" href="#home">
                        &lt;&lt;
                    </a>
                    <a data-role="button" data-inline="true" data-direction="reverse" data-transition="fade" href="#child">
                        &gt;&gt;
                    </a>
                </div>
                <div data-role="content">
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup" data-mini="true">
                            <label for="textinput1">
                                User:
                            </label>
                            <input id="textinput1" placeholder="Khushu" type="text" />
                        </fieldset>
                    </div>
                    <input data-theme="d" ="submitbtn" value="Login" type="submit"  onSubmit="redirect()"/>
                </div>
                <div data-theme="a" data-role="footer" data-position="fixed" >
                    <h3>
                        Page1
                    </h3>
    
                    </div>
            </div>
    
            <div data-role="page" id="child">
                <div data-theme="d" data-role="header">
                    <h3>
                        The Grand Bhagvati
                    </h3>
                    <a data-role="button" data-inline="true" data-direction="reverse" data-transition="slide" >
                        &lt;&lt;
                    </a>
                    <a data-role="button" data-inline="true" data-direction="reverse" data-transition="fade" >
                        &gt;&gt;
                    </a>
                </div>
                <div data-role="content">
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup" data-mini="true">
                            <label for="textinput1">
                                User:
                            </label>
                            <input id="textinput1" placeholder="Khushu" type="text" />
                        </fieldset>
                    </div>
                    <input data-theme="d" value="Login" type="submit"  onsubmit="redirect()"/>
                </div>
                <div data-theme="a" data-role="footer" data-position="fixed" >
                    <h3>
                        Page1
                    </h3>
    
                    </div>
            </div>
    

  • 请参考下面的代码,我正在学习 jquery,我想显示 使用javascript/jquery点击提交按钮时名为#child的标签,任何人都可以帮助我如何调用按钮点击

  • 还想打电话给#child 和#home>>(next button) & <<(prev button)** on button click分别在代码中>>和<<的标记写为<和&glt。?谁能帮我吗 ?

            <div data-role="page" id="home">
                <div data-theme="d" data-role="header">
                    <h3>
                        The Grand Bhagvati
                    </h3>
                    <a data-role="button" data-inline="true" data-direction="reverse" data-transition="slide" href="#home">
                        &lt;&lt;
                    </a>
                    <a data-role="button" data-inline="true" data-direction="reverse" data-transition="fade" href="#child">
                        &gt;&gt;
                    </a>
                </div>
                <div data-role="content">
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup" data-mini="true">
                            <label for="textinput1">
                                User:
                            </label>
                            <input id="textinput1" placeholder="Khushu" type="text" />
                        </fieldset>
                    </div>
                    <input data-theme="d" ="submitbtn" value="Login" type="submit"  onSubmit="redirect()"/>
                </div>
                <div data-theme="a" data-role="footer" data-position="fixed" >
                    <h3>
                        Page1
                    </h3>
    
                    </div>
            </div>
    
            <div data-role="page" id="child">
                <div data-theme="d" data-role="header">
                    <h3>
                        The Grand Bhagvati
                    </h3>
                    <a data-role="button" data-inline="true" data-direction="reverse" data-transition="slide" >
                        &lt;&lt;
                    </a>
                    <a data-role="button" data-inline="true" data-direction="reverse" data-transition="fade" >
                        &gt;&gt;
                    </a>
                </div>
                <div data-role="content">
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup" data-mini="true">
                            <label for="textinput1">
                                User:
                            </label>
                            <input id="textinput1" placeholder="Khushu" type="text" />
                        </fieldset>
                    </div>
                    <input data-theme="d" value="Login" type="submit"  onsubmit="redirect()"/>
                </div>
                <div data-theme="a" data-role="footer" data-position="fixed" >
                    <h3>
                        Page1
                    </h3>
    
                    </div>
            </div>
    

回答by Gwyn Howell

To show a tag use

显示标签使用

$('#child').show();  // where child is the id of the element

and to hide ...

并隐藏...

$('#child').hide();

alternatively, you can simply toggle it between hide/show as follows:

或者,您可以简单地在隐藏/显示之间切换,如下所示:

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

to attach these to an onclick event of a button ...

将这些附加到按钮的 onclick 事件...

$(document).ready(function() {
    $('#buttonID').click(function() {
        $('#child').toggle();
    });
});

hope this helps

希望这可以帮助

回答by Mathew Paul

The below code is for javascript

以下代码适用于 javascript

var Home= document.getElementById("home");

var Home= document.getElementById("home");

Home.style.display="none";//To hide the div
Home.style.display="";//To display the div

回答by Owais Alam

Try this in your script
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("#hide").click(function(){
    $("p").hide();
  });
  $("#show").click(function(){
    $("p").show();
  });
});
</script>
</head>
<body>
<button id="hide">Hide</button>
<button id="show">Show</button>
</body>
</html>