2015-06-19 47 views
0

我試圖用jQuery來動畫頁面上的每個按鈕,然後在span標籤中顯示該按鈕的值。 JShint顯示沒有語法錯誤,但代碼不起作用,將不勝感激。jquery animate()函數遇到問題

jQuery代碼:

$('button').click(function() { 
    $(this).animate({ 
      'background-color': '#142900', 
      'width': '50px', 
      'height': '30px' 
     }, 
     1000, 
     function() { 
      $('.screen').val($(this).val()); 
     }); 
}); 

HTML代碼:

<body> 
    <div class="calculator_area"> 
     <h1>Below you see a fully functional calculator. Ready to get get your hands dirty?!</h1> 
     <span class="screen"></span> 
     <div class="calculator"> 
      <button>1</button> 
      <button>2</button> 
      <button>3</button> 
      <br> 
      <button>4</button> 
      <button>5</button> 
      <button>6</button> 
      <br> 
      <button>7</button> 
      <button>8</button> 
      <button>9</button> 
      <br> 
      <button>0</button> 
      <button>+</button> 
      <button>-</button> 
      <br> 
      <button>x</button> 
      <button>/</button> 
      <button>=</button> 
     </div> 
    </div> 
</body> 

回答

1

$('.screen').val($(this).val());

應該是:

$('.screen').text($(this).text());

既然您的<span><button>元素都沒有value屬性。

+0

耶!它的工作原理,謝謝! – Gocha

+0

@Smartboy如果回答您的問題,您是否願意接受答案? –