【发布时间】:2013-12-04 16:39:44
【问题描述】:
我试图创建可点击的文本(并最终)创建一个可以在定义区域中生成文本的自创按钮。当我点击“这将生成文本”时,它会在那里闪烁一秒钟然后消失。
注意:最后会有多个按钮在同一个区域生成文本,所以我需要替换文本。
CSS
#wrapper {
margin: 0px;
height: 500px;
width: 500px;
}
a:hover{
color: #0FC;
}
#button {
height: 100px;
width: 100px;
float:left
}
#text{
margin: 0px;
height: 495px;
width: 395px;
float:left;
border-style:solid;
border-width:thin;
}
Javascript
<script>
function myFunction()
{
document.getElementById("text").innerHTML="My First JavaScript Function";
}
</script>
</head>
HTML
<body>
<div id="wrapper">
<div id="button">
<p><a href="">
<span onclick="myFunction()">This will generate the text</span>
</a></p>
</div>
<div id="text"></div>
</div>
</body>
【问题讨论】:
-
你为什么不用 jquery 试试这个呢?这需要更容易。
标签: javascript html button text