0

私は全体としてjqueryとjavascriptが初めてです。私は2つのことを試みましたが、そのうちの1つだけが機能しています。以下で説明するように、色を変更するだけでなく、カウンターを増やす必要があります。コードのヘルプが必要です。例 -

1 click - 1
2 clicks - 11
5 clicks - 11111

コード - HTML

<div id="flash"> <p>hello</p>
    </div>
<div id="counter">0</div>​

コード - JAVASCRIPT

$(document).ready(function() {
$('p').click(function() {
    $(this).animate({
        'color': 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')'
    }, 500);
});
$("#flash").click(function() {
    $('#counter').html(function(i, val) {
        return val * 1 + 1;
    });
});
});​

コード - CSS

p { font-weight: bold; display: inline; cursor: pointer; }​

これが私が試してみた私のコードです - http://jsfiddle.net/crlf/pVHYc/

4

2 に答える 2

2

色をアニメーション化するにはjQueryUIを含める必要があります.animate()

s を連結できるカウンターについては、1それがそうであるかどうかを確認し、 a0に置き換える1か連結し1ます。

return val =='0'?1: val + 1; 

http://jsfiddle.net/pVHYc/6/を参照してください

于 2012-10-29T06:04:32.547 に答える
0

アニメーションと出力の問題の両方を解決しました。

アニメートはjquery UIが含まれていないためです

追加しようとしているが連結を試みているため、出力が間違っています

http://jsfiddle.net/pVHYc/4/

$(document).ready(function() {
 $('p').click(function() {
    $(this).animate({
        'color': 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')'
    }, 500);
});
$("#flash").click(function() {
    $('#counter').html(function(i, val) {
        return val * 1 + 1;
    });
});
});
于 2012-10-29T06:16:07.973 に答える