我是 html 的新手,这是我们的第一个 javascript 入门作业;所以我很自然地吓坏了!这是我正在谈论的示例:
<div class="someclassname"> <a href="image.jpg">
<img src= Image/image.jpg height="80">
</a>
<p>some text to he hidden with the image!</p>
</div>
我到处都找过类似的东西,但我无法将其转化为我正在做的事情
我在想代码应该看起来像这样吗?
<script>
$(document).ready(function() {
$("Button").click(function() {
$(".someclassname").toggle();
if ($.trim($(this).text()) == 'Hide') {
$(this).text('Show');
} else {
$(this).next('Hide');
}
});
</script>
我接近了吗?请帮忙!
最佳答案
你已经足够接近了......
您的脚本中存在语法错误,缺少一对 })
然后在您的 html 中放置一个按钮
$(document).ready(function() {
$("button").click(function() {
$(".someclassname").toggle();
if ($.trim($(this).text()) == 'Hide') {
$(this).text('Show');
} else {
$(this).next('Hide');
}
});
}); //this is missing
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button>Hide</button>
<div class="someclassname">
<a href="image.jpg">
<img src="Image/image.jpg" height="80" />
</a>
<p>some text to he hidden with the image!</p>
</div>
关于javascript - 单击按钮隐藏或取消隐藏文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28868009/