jQuery,按钮消息不会改变 [英] jQuery, button message doesn't change

查看:87
本文介绍了jQuery,按钮消息不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何让我的按钮旁边的文字更改?除了这些按钮消息外,其他一切正常。感谢您的帮助。


How do I get the text beside my button to change? Everything else works fine except for these button messages. Thanks for your help.

<!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>

BUTTON STATE'消息应在较大文本之间切换较小text '

BUTTON STATE 'Message should toggle between Larger Text and Smaller text'

[+] 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(); to $(body h6)。toggle();并将其移至$('#PlusMinus')。点击功能

changed $("h6").toggle(); to $("body h6").toggle(); and moved it up to the $('#PlusMinus').click function

将按钮移出较大文本h6元素

moved the button out of the "Larger Text" h6 element

已添加<顶部的html>标记

added < html > tag at the top

删除了不工作评论;)

这篇关于jQuery,按钮消息不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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