weixin_33728268 2016-04-20 18:56 采纳率: 0%
浏览 34

innerHTML.value不起作用?

I've been trying to write a JavaScript program that returns Wikipedia search results. A few days ago, I got it to the point where I could see the item being searched for, as confirmed by the alert() method, but now when I call the same alert() method it just returns "undefined":

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

I swear that this is exactly what I had while it was working, so there must be some subtle issue elsewhere. Any help is appreciated, complete code below:

HTML:

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

JavaScript:

   $(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);
   }
 });

  })    
  • 写回答

2条回答 默认 最新

  • weixin_33733810 2016-04-20 18:58
    关注
    • Use .innerHTML to get the html in a DOM element
    • Use .value to get the value of an input, textarea, or other form input

    .innerHTML.value is not a thing.

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题