笑故挽风 2015-11-24 18:49 采纳率: 100%
浏览 141

获取<div>标签的值

I am interested in when choosing an option from a drop-down list the value of the selected option that stá visualiando in a < div > that value is captured in a javascript variable. The list referred to originated in an AJAX routine that queries a database. On page php , where there is a div shown above . I need your help to take this value from the list.

  • 写回答

1条回答 默认 最新

  • DragonWar% 2015-11-24 19:48
    关注

    Assuming that you meant for your question read the way RightClick explained it in the comments, you need something like this:

    window.onload = function() {
    var ids = $('.dropdown').map(function(){
        return this.id;
    }).get();//Get array of ids
    
    
        var options = document.getElementsByClassName('dropdown');
        for(var i = 0; i < options.length; i++) {
            var anchor = options[i];
            anchor.onclick = function() {
                var h = new XMLHttpRequest();
                h.open("GET", "/myDB?q="+ids[i], true);//This should be synchronous
                h.send();
                document.getElementById("responseDiv").innerHTML = h.responseText;
            }
        }
    }
    

    `

    评论

报告相同问题?