如何让我的按钮旁边的文本发生变化? 除了这些按钮消息外,其他一切都正常。感谢您的帮助。
<!DOCTYPE html PUBLIC "><head>
<script type="text/javascript" src="js/jquery-1.4.min.js"></script>
<script type='text/javascript'>
var fontSizes = [14, 16]
$(function(){
$('#PlusMinus').click(function() {
if($(this).val() == "+") {
$('#OurText').css('fontSize', fontSizes[1] + 'pt');
$(this).val("-");
}else {
$('#OurText').css('fontSize', fontSizes[0]+ 'pt');
$(this).val("+");
}
});
});
<!--NOT WORKING-->
$("button").click(function () {
$("h6").toggle();
});
</script>
</head>
<!--NOT WORKING-->
<h6>
<input type='button' value='+' id='PlusMinus'/>
Larger Text</h6>
<h6 style="display: none">Smaller Text</h6>
<!--TEXT RESIZES-->
<p id="OurText">My Text!!!</p>
</body>
</html>
按钮状态“消息应该在大文本和小文本之间切换”
[+] Larger Text
[-] Smaller Text
最佳答案
这对我有用:
<!DOCTYPE html PUBLIC "><html>
<head>
<script type="text/javascript" src="jquery-1.4.min.js"></script>
<script type="text/javascript">
var fontSizes = [14, 16]
$(function(){
$('#PlusMinus').click(function() {
if($(this).val() == "+") {
$('#OurText').css('fontSize', fontSizes[1] + 'pt');
$(this).val("-");
}else {
$('#OurText').css('fontSize', fontSizes[0]+ 'pt');
$(this).val("+");
}
$("body h6").toggle();
});
});
</script>
</head>
<input type='button' value='+' id='PlusMinus'/>
<h6>Larger Text</h6>
<h6 style="display: none">Smaller Text</h6>
<!--TEXT RESIZES-->
<p id="OurText">My Text!!!</p>
</body>
</html>
我所做的更改是:
改变了 $("h6").toggle();到 $("body h6").toggle();并将其移至 $('#PlusMinus').click 函数
将按钮移出“Larger Text”h6 元素
在顶部添加了标签
删除了“不工作”的评论;)
关于javascript - jQuery,按钮消息不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5216063/