开发者

How to set div value

How do I set the value/text of a div?

<div id="numberOf"></div>

$("#btn").click(function (event) {
  $.getJSON('h开发者_StackOverflowttp://host/myServiceImpl.svc/GetCount?method=?',
    { id '1' },
    function (data) {
      alert(data);
      $("#numberOf").val = data;
    }
  );
});


Text: http://api.jquery.com/text/

$("#numberOf").text(data);

Html: http://api.jquery.com/html/

$("#numberOf").html(data);


  • http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=jquery+text+div
  • http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=how+do+i+set+the+value/text+of+a+div%3F

^ Google gives you everything you need. I would suggest googling before asking.

So to answer, you'd want

$('#numberOf').text(data) 

or

$('#numberOf').html(data)


or

$('#numberOf').html(data);


Set the text property...

$("#btn").click(function (event) {
                $.getJSON('http://host/myServiceImpl.svc/GetCount?method=?', { id '1' },
                function (data) {
                    alert(data);
                    $("#numberOf").text(data);

                });
            });


if your value is a pure text (like 'test') you could use the text() method as well. like this:

 $('#numberOf').text(data); Or $('#numberOf').html(data);

Both are working fine.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜