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

javascript - Remove an html button using js - Stack Overflow

programmeradmin2浏览0评论

I have a bit of code below that creates a button on a html form. When a user has entered some information using the button I want the form to reflect this by removing the button and replacing it with just plain text. I have tried getting the inner html and using divs but nothing is working can anybody help please? I am not looking for anyone to write code for me just a few pointers would be great.

  <td class="col1"><h3>Associated with :</h3></td>
  <td class="col3">
  <input type="button" 
  value="Associate this job " 
  onclick="associate()" 
/></td>

I have a bit of code below that creates a button on a html form. When a user has entered some information using the button I want the form to reflect this by removing the button and replacing it with just plain text. I have tried getting the inner html and using divs but nothing is working can anybody help please? I am not looking for anyone to write code for me just a few pointers would be great.

  <td class="col1"><h3>Associated with :</h3></td>
  <td class="col3">
  <input type="button" 
  value="Associate this job " 
  onclick="associate()" 
/></td>
Share Improve this question edited Sep 5, 2022 at 14:08 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Aug 17, 2010 at 21:27 MickMick 2,89810 gold badges48 silver badges64 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

Add a span with an idattribute around whatever it is you want to change. When it's time, here's all you need to do:

    document.getElementById("spanIDhere").innerHTML = "Your text here";

So for instance, you'd have the line:

    <span id="associatespan">
        <input type="button" value="Associate this job" onclick="associate()" />
    </span>

and your script would say:

    document.getElementById("associateSpan").innerHTML = "Look, no more button!";

Put it in a DIV and put the text in a DIV that is hidden. When the user starts to type, hide the button DIV and show the text DIV.

I suggest that you look at one of the Javascript toolkits that make it very easy. For example, I have used Prototype for this. The specific method is Element.hide() and there's example usage on the page.

发布评论

评论列表(0)

  1. 暂无评论