我正在尝试使用jQuery为页面上的每个按钮设置动画,然后在span标记中显示该按钮的值。 JShint显示没有语法错误,但代码不起作用,将不胜感激。
jQuery代码:
$('button').click(function() {
$(this).animate({
'background-color': '#142900',
'width': '50px',
'height': '30px'
},
1000,
function() {
$('.screen').val($(this).val());
});
});
HTML code:
<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>
答案 0 :(得分:1)
$('.screen').val($(this).val());
应该是:
$('.screen').text($(this).text());
由于您的<span>
和<button>
元素都不具有value
属性。