获取标记的值[英]get the value of an tag 本文翻译自  Rafael Prado  查看原文  2015-11-24  60    php/ html/

时间:2021-08-17 08:45:04

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.

我感兴趣的是从下拉列表中选择一个选项的值,该选项是在一个javascript变量中捕获的值

中的stávisualiando的值。引用的列表源自查询数据库的AJAX例程。在页面php,上面有一个div。我需要你的帮助才能从列表中获取此值。

1 个解决方案

#1


1  

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

假设你的问题意味着阅读RightClick在评论中解释它的方式,你需要这样的东西:

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;
        }
    }
}

`

`

#1


1  

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

假设你的问题意味着阅读RightClick在评论中解释它的方式,你需要这样的东西:

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;
        }
    }
}

`

`