我有一个textarea:onClick textfield显示一个div?
<textarea cols="10" rows="5">Type in the text</textarea>
我想要显示的文本区域下方的股利(或<span>
)时的onclick上textarea的。
我怎么能这样做?
此外,我想隐藏它在div(或跨度)单击链接时。
我有一个textarea:onClick textfield显示一个div?
<textarea cols="10" rows="5">Type in the text</textarea>
我想要显示的文本区域下方的股利(或<span>
)时的onclick上textarea的。
我怎么能这样做?
此外,我想隐藏它在div(或跨度)单击链接时。
最基本的方法就是给一个ID的跨度,然后:
<textarea cols="10" rows="5" onclick="document.getElementById('box').style.display='inline';">Type your text here</textarea>
<span id="box" style="display:none">display</span>
谢谢...这工作! :) – Akos
如果你使用jQuery那么它很简单:
$("textarea").bind("focus", function(){
$("span").show();
});
随后的链接给它一个ID在HTML:
<span>
<a href="#" id="closeme">Close me</a>
</span>
然后:
$("#closeme").bind("click", function(){
$("span").hide();
});
记住Javascript必须进入<script></script>
标签,并确保您在页面中包含jQuery:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
如果你是新来的jQuery那么下面这段代码应该给你如何开始的想法。一般来说,最好还是指使用ID,而不是他们的标签名,如textarea
和span
的元素 - 它将意味着JavaScript就瞄准正确的元素..像这样的东西会做你问什么:
<html lang="en">
<body>
<textarea id="form-details"></textarea>
<span id="form-details-info">
Some info about the textarea
<br/>
<a href="#">Close text area</a>
</span>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(function(){
// When a user is using the textarea
$("#form-details").bind("focus", function(e){
// Show the span info
$("#form-details-info").show();
});
// When a user clicks the close link
$("#form-details-info a").bind("click", function(e){e){
// Hide the info
$("#form-details-info").hide();
// And use this to stop a prevent a link from doing what it normally does..
e.preventDefault();
});
});
</script>
</body>
</html>
是跨度已经存在或者是你在飞行中产生的呢?另外,你到目前为止还有什么? – pimvdb
跨度已经存在。它隐藏着:style =“display:hidden;” – Akos