开发者

pass data using jquery $.get()

I try to implement the following code:

html

   <span id = "myset">school</span>

Javascript

      var myset =$("#myset").val();
        var ID=$("#data li:last").attr("id");
    $.get('page.php', 'id='+ID+'&set='+myset, function(newdata){
        $('#data').append(newdata);

    });

In the page.php file, it doesn't receive the value of the $_GET['set'], but if I change

      var myset =$("#myset").val();

to:

       var myset ='school';

everything works fine in this case, what am I doing wrong, anyone could help me, thanks. I also tried

       var myset =document.getElementById("myset"开发者_C百科).value;

but it is still not working;


Span tags don't have a value, they have .innerText or .innerHTML or, with jQuery, .html() or .text()


"school" isn't the value of your span. It is the data of a text node inside your span. You can access it like this:

var myset = $("#myset").text();


Use var myset =$("#myset").text(); instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜