Javascript innerHTML.value不工作?

Javascript innerHTML.value不工作?,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我一直在尝试编写一个JavaScript程序,返回维基百科的搜索结果。几天前,正如alert()方法所确认的那样,我可以看到正在搜索的项目,但现在当我调用相同的alert()方法时,它只返回“undefined”: 我发誓这正是我在它工作时所拥有的,所以在其他地方肯定有一些微妙的问题。如需任何帮助,请填写以下代码: HTML: 使用.innerHTML获取DOM元素中的html 使用.value获取输入、文本区域或其他表单输入的值 .innerHTML.value不是一件事。如果您使用的是

我一直在尝试编写一个JavaScript程序,返回维基百科的搜索结果。几天前,正如alert()方法所确认的那样,我可以看到正在搜索的项目,但现在当我调用相同的alert()方法时,它只返回“undefined”:

我发誓这正是我在它工作时所拥有的,所以在其他地方肯定有一些微妙的问题。如需任何帮助,请填写以下代码:

HTML:

  • 使用
    .innerHTML
    获取DOM元素中的html
  • 使用
    .value
    获取
    输入
    文本区域
    或其他表单输入的值

.innerHTML.value
不是一件事。

如果您使用的是
jQuery
,请尝试以下操作:

var search = $("#test").html();
alert(search);

innerHTML
没有
的.value
。它本身就是元素的innerHTML;警报(搜索)输入没有innerhtml。。。
  <a href="http://en.wikipedia.org/wiki/Special:Random">Random</a>
  <section>
  <form>
  <br>
  <div class="divid">
       <input type="text" value=''  id="test" >
       <button >Search</button>
  </div>
  </form>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
   $(document).ready(function () {

   $("button").click(function(e){
   var search =document.getElementById("test").innerHTML.value;
       alert(search);
   });

   var button = $('button');
   var toSearch = '';
   var searchUrl = "http://en.wikipedia.org/w/api.php"
   var x="England"; 

   input.autocomplete({
    source: function (request, response) {
        $.ajax({
            url: searchUrl,
            dataType: 'jsonp',
            data: {
                'action': "opensearch",
                'format': "json",
                'search': request.term
            },
            success: function (data) {
                response(data[1]);
            }
        });

        }

       });      


    var playListURL = 'http://en.wikipedia.org/w/api.php?format=json&action=query&titles=India&prop=revisions&rvprop=content&callback=?';
    $.getJSON(playListURL ,function(data) {
       $.each(data.query.pages, function(i, item) {
         //alert(item.title);
       })
    })

     $.ajax({  
//http://en.wikipedia.org/w/api.php?format=json&action=query&titles=India&prop=revisions&rvprop=content&callback=?
   url: '//en.wikipedia.org/w/api.php',
   data: { action: 'query', list: 'search', srsearch: "Carl Sagan", format: 'json' },
    dataType: 'jsonp',
    success: 
     function (x) {
       //alert( x.query.search[0].title);
   }
 });

  })    
var search = $("#test").html();
alert(search);