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

javascript - How to display second button after the click on first button? - Stack Overflow

programmeradmin3浏览0评论

How to display second button after the click on first button??

I mean, when The user clicks on one button, he should see another button, on click of which he should return to his previous button!! Cyclic event kind of... I wanted to do this using Java script and HTML.

I tried to use 'onclick' but it dint work!! Help!!

This is what I used..

    `<body>

 function alert()
{
  alert("54");
    // <input type="button" id="btnSer" value="Back"/>
}

  <input type="button" id="btnSearch" value="Search" onClick="alert();">


</body>`

How to display second button after the click on first button??

I mean, when The user clicks on one button, he should see another button, on click of which he should return to his previous button!! Cyclic event kind of... I wanted to do this using Java script and HTML.

I tried to use 'onclick' but it dint work!! Help!!

This is what I used..

    `<body>

 function alert()
{
  alert("54");
    // <input type="button" id="btnSer" value="Back"/>
}

  <input type="button" id="btnSearch" value="Search" onClick="alert();">


</body>`
Share Improve this question edited Sep 18, 2011 at 18:31 fireshadow52 6,5262 gold badges32 silver badges48 bronze badges asked Sep 18, 2011 at 18:25 RahulRahul 11 gold badge1 silver badge2 bronze badges 1
  • You can use jQuery, for example – Alex K Commented Sep 18, 2011 at 18:28
Add a ment  | 

2 Answers 2

Reset to default 3

Something like this?

<button id="button1" style="display:block;" onclick="document.getElementById('button2').style.display = 'block'; this.style.display = 'none';">Button 1</button>
<button id="button2" style="display:none;" onclick="document.getElementById('button1').style.display = 'block'; this.style.display = 'none';">Button 2</button>

here is the code using simple plain javascript : (*note that naming your function alert() isnt smart because there is already a predefined function in js called alert)

Javascript Code

function addBtn(){
  document.getElementById('btnHolder').innerHTML = '<input type="button" onClick="javascript:removeBtn();" value="click" />';
}

function removeBtn(){
  document.getElementById('btnHolder').innerHTML = '';
}

HTML

<div id="btnOne"><input type="button" onClick="javascript:addBtn();" value="click" /></div>
<div id="btnHolder"></div>

this code is not tested but it should work, let me know if you have any other questions

发布评论

评论列表(0)

  1. 暂无评论