的onClick文本更改 [英] onClick text change

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

问题描述

所以我pretty新的HTML和需要一些帮助。

我试图让3个按键和他们每个人的旁边,当你点击它们将改变文本。我使用下面的code为每个按钮:

 < A HREF =#的onClick =的document.getElementById('过去')的innerHTML ='---未来---'。>




当我点击按钮上的文本将在的innerHTML =后的文字改变。问题是,一个我加入太多文字的地方---未来---它不会再在浏览器中加载它。屏幕就不会更新。我该如何解决这个问题?我一直有相当一段时间,因此任何帮助将appriciated这个问题。


解决方案

 < p n =窥视>< / P><按钮的onclick =myFunction的('哈利·波特')>点击哈利波特< /按钮>
<按钮的onclick =myFunction的('鲍勃')>点击鲍勃< /按钮><脚本>
函数myFunction的(名字)
{
。的document.getElementById(窥视)的innerHTML =欢迎+名称;
}
< / SCRIPT>

使用上的所有按钮的相同功能更改文本!

勾选此小提琴

so I'm pretty new with html and need some help.

I'm trying to make 3 buttons and each of them will change the text next to when you click on them. I am using the following code for each button:

<a href="#" onClick="document.getElementById('past').innerHTML='---future---';">

When I click on the button the text will change in the text after the innerHTML=" ". The problem is that one I add to much text on the places ---future--- it won't load it anymore in the browser. The screen just won't update. How do I overcome this problem? I've been having this problem for quite some time so any help will be appriciated.

解决方案

<p id="peep"></p>

<button onclick="myFunction('Harry Potter')">Click for Harry Potter</button>
<button onclick="myFunction('Bob')">Click for Bob</button>

<script>
function myFunction(name)
{
document.getElementById("peep").innerHTML = "Welcome " + name;
}
</script>

Use the same function on all buttons to change the text!

Check this fiddle.

这篇关于的onClick文本更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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