开发者

assign value to div returning from JSON result

i have one div whois id is generated in php in one loop.

    <div align="left" id="BalBox<?php echo $row['pid']; ?>" 
class="text_balance">Balance: 
    </div>

where pid will be 1, 2, 3 etc

now i have JSON as bellow, in this JSON second optionDisplay is actually pid and first optionValue is value after calculation in php file.

    [{optionValue:12, optionDisplay:1},{optionValue:0, optionDisplay:2}
,{optionValue:0, optionDisplay:3},]

now what i need is,

Display 12 on BalBox1 , as optionDisplay:1 is for BalBox and optionValue is for value, so now value of BalBox1 will be Balance: 12, same like this for all in JSON result.

here is my jquery code..

$.getJSON("page.php",{id: $(this).val(), ajax: 'true'}, function(j){
     var options = '';
     for (var i = 0; i < j.length; i++) {
       $('#BalBox'+开发者_JAVA百科j[i].optionDisplay).val("Balance: " +j[i].optionValue);
     }

but its not working... i mean its not showing or changing any thing...

Thanks


erm. did you alert the values of j to check if they're set?

and you should use .html() instead of .val() since you're trying to edit DIV's and not INPUT's

cheers :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜