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; } } }
`
解决 无用评论 打赏 举报