vostro Posted November 9, 2011 Report Share Posted November 9, 2011 (edited) Doma ir tāda, kad skaitlis ir -1 tad ar JQuery palīdzību pievienot klasi addClass, kur skaitlis būs sarkans, kā, vai ar kādu metodi var noteikt, kad skaitlis ir negatīvs? Vēlos tādu rezultātu: Novērtējums: <span id="rating">3</span> Novērtējums: <span id="rating">-1</span> Edited November 9, 2011 by vostro Quote Link to comment Share on other sites More sharing options...
entu Posted November 9, 2011 Report Share Posted November 9, 2011 Pārmaini id uz class un šis ir viens no risinājumiem. $(document).ready(function(){ $(".rating").each(function(){ if( parseInt($(this).html()) < 0 ) { $(this).addClass("red"); } else { $(this).addClass("green"); } }) }) Quote Link to comment Share on other sites More sharing options...
vostro Posted November 9, 2011 Author Report Share Posted November 9, 2011 Paldies entu Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.