[Hỏi đáp] Thay đổi code hiển thị thanh level.

  Bài viết hay nhất1
Mình có đoạn JS sau:

Code:
<script type="text/javascript">
var code="level";
  function level(Posts,Coins,Thanked){var d=(Coins*55);var e=(d/1500);var f=Math.floor((e-Math.floor(e))*100);var g=Math.floor(e+parseInt(1));var h=(Math.floor((Thanked*10)+(Posts*2)+(Coins*1)));if(h>8000){h=8000};if(d>25000){(d=25000)};var i=(Coins*55);var j=(Math.floor((d/25000)*69)-2);var p=(Math.floor((d/25000)*30)-2);var k=(Math.floor((d/25000)*89)-2);var v=(Math.floor((d/2500)*99)*100);document.write('<div style="width: 150px; margin-right: 10px; margin-top: -10px;"><b><font color=orange> Tài năng : </font></b>('+v+')<div class=""><div class=""><fieldset style="padding: 1px;border: 1px solid #666;border-radius: 3px 3px 3px 3px;"><img src="/users/2211/12/43/96/album/orange10.gif" width="'+j+'%" title="'+d+'" height="9px"><img src="/users/2211/12/43/96/album/hp1010.gif" width="2px" title="'+d+'" height="9px"></fieldset></div></div><b><font color=green> Danh vọng : </font></b>('+h+')<div class="abilitybg"><div class="abilitybg2"><fieldset style="padding: 1px;border: 1px solid #666;border-radius: 3px 3px 3px 3px;"><img src="/users/2211/12/43/96/album/green110.gif" width="'+k+'%" title="'+h+'" height="9px"><img src="/users/2211/12/43/96/album/mp1010.gif" width="2px" title="'+h+'" height="9px"></fieldset></div></div><font color=RoyalBlue1> <b> Hoạt động :</b></font> ('+f+')<div class="expbg"><div class="expbg2"><fieldset style="padding: 1px;border: 1px solid #666;border-radius: 3px 3px 3px 3px;"><img src="/users/2211/12/43/96/album/blue1010.gif" width="'+p+'%" title="'+(f)+'%" height="9px"><img src="/users/2211/12/43/96/album/exp1010.gif" width="2px" title="'+(f)+'%" height="9px"></div></div></fieldset></div>')};
</script>

Và mình muốn sửa nó lại để hiển thị nơi có...

Code:
<div class="level"></div>

...Liệu có khả quan?

P/s: Thx vì đã ghé thăm topic :D
The author of this message was banned from the forum - See the message
  Bài viết hay nhất3
sửa chỗ document.write lại thôi
Code:
  function level(Posts, Coins, Thanked) {
      var d = (Coins * 55);
      var e = (d / 1500);
      var f = Math.floor((e - Math.floor(e)) * 100);
      var g = Math.floor(e + parseInt(1));
      var h = (Math.floor((Thanked * 10) + (Posts * 2) + (Coins * 1)));
      if (h > 8000) {
          h = 8000
      };
      if (d > 25000) {
          (d = 25000)
      };
      var i = (Coins * 55);
      var j = (Math.floor((d / 25000) * 69) - 2);
      var p = (Math.floor((d / 25000) * 30) - 2);
      var k = (Math.floor((d / 25000) * 89) - 2);
      var v = (Math.floor((d / 2500) * 99) * 100);
      document.write('<div style="width: 150px; margin-right: 10px; margin-top: -10px;"><b><font color=orange> Tài năng : </font></b>(' + v + ')<div class=""><div class=""><fieldset style="padding: 1px;border: 1px solid #666;border-radius: 3px 3px 3px 3px;"><img src="/users/2211/12/43/96/album/orange10.gif" width="' + j + '%" title="' + d + '" height="9px"><img src="/users/2211/12/43/96/album/hp1010.gif" width="2px" title="' + d + '" height="9px"></fieldset></div></div><b><font color=green> Danh vọng : </font></b>(' + h + ')<div class="abilitybg"><div class="abilitybg2"><fieldset style="padding: 1px;border: 1px solid #666;border-radius: 3px 3px 3px 3px;"><img src="/users/2211/12/43/96/album/green110.gif" width="' + k + '%" title="' + h + '" height="9px"><img src="/users/2211/12/43/96/album/mp1010.gif" width="2px" title="' + h + '" height="9px"></fieldset></div></div><font color=RoyalBlue1> <b> Hoạt động :</b></font> (' + f + ')<div class="expbg"><div class="expbg2"><fieldset style="padding: 1px;border: 1px solid #666;border-radius: 3px 3px 3px 3px;"><img src="/users/2211/12/43/96/album/blue1010.gif" width="' + p + '%" title="' + (f) + '%" height="9px"><img src="/users/2211/12/43/96/album/exp1010.gif" width="2px" title="' + (f) + '%" height="9px"></div></div></fieldset></div>')
  };
  Bài viết hay nhất4
Mình chèn thẳng đoạn js của Zero vào view nhưng nó ko hoạt động Zero à :)
  Bài viết hay nhất5
Chạy cái function + đổi document.write chưa?

1) Cái .level trong mỗi post nó có 1 cái, nên bạn chạy loops rồi chèn cái đó vào. Làm như vậy cái script nó biết đang muốn sử dụng cái .level nào
2) Loops làm như sau
jquery
Code:
$(function () {
$('.level').each(function() { // <--- loops
$(this).append(level(Posts, Coins, Thanked));
});
js
Code:

a = documents.getElementsByClassName('level');
for(i=0;i<a.length;i++) { // <--- loops
a[i].innerHTML = level(Posts, Coins, Thanked);
}
3) Đổi cái document.write thành return, xoá 2 cái ( )
4) Bổ sung variable Posts, Coins, Thanked bị thiếu
  Bài viết hay nhất6
You cannot reply to topics in this forum