Coffeescript
1$("#button").click -> 2 x++ 3 if x >=10 && $('li.no:first-child').length <1 4 $("ul.nunbers").append('<li class="no" style="background:yellow;"></li>') 5 else if x >=15 && $('li.no:nth-child(2)').length <1 6 $("ul.nunbers").append('<li class="no" style="background:green;"></li>') 7 else
html
1<ul class="numbers"></ul> 2<input type="button" id="button">
上記のようにボタンをクリックすると内部処理でxが加算され、xがそれぞれ10、15になるとul内にliの黄色と緑が1つずつ追加される処理を行いたいのですが、このままだと10に加算された際、ボタンを押すたびに11以降もliタグの黄色が追加されてしまうのですがどうすればよいでしょうか?
回答1件
あなたの回答
tips
プレビュー