onClick用新的javascript元素替换javascript元素 [英] onClick replace javascript element, with new javascript element

查看:84
本文介绍了onClick用新的javascript元素替换javascript元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚的是如何制作一个按钮,当你点击时,将会用一个文本框替换它自己。我在W3Schools网站上发现了这个代码,并且无法弄清楚如何将javascript(或HTML)元素放入。


What I am trying to figure out is how to make a button, that when you click, will replace itself with a textbox. I found this code on the W3Schools website, and can't figure out how to put javascript (or HTML) elements in.

<p>Click the button to replace "Microsoft" with "W3Schools" in the paragraph below:</p>

<p id="demo">Visit Microsoft!</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var str = document.getElementById("demo").innerHTML; 
    var res = str.replace("Microsoft", "W3Schools");
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>
</html>
<input type="text" name="textbox" value="textbox"><br>

最后,我希望能够用HTML标记之外的文本框替换按钮

In the end I want to be able to replace a button with the textbox I put outside the html tags

推荐答案

我最终找到了一个可以在 http://www.webdeveloper.com/forum/showthread.php?266743-Switch-Div-Content-Using- Javascript

I ended up finding a code that works off of http://www.webdeveloper.com/forum/showthread.php?266743-Switch-Div-Content-Using-Javascript

这篇关于onClick用新的javascript元素替换javascript元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆