请问老师为什么点击后没反应,哪里错了?

来源:3-6 自由编程

慕先生2101995

2019-03-08 15:21:11

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/js/jquery-3.3.1.js"></script>
<script type="text/javascript">
  $(function(){
   $.ajax({
    "url":"/ajax/song",
    "type":"get",
    "dataType":"json",
    "success":function(json){
     $("#fashion").click(function(){
      for(int i = 0;i<json.length;i++){
       document.getElementById("fashion-song").innerHTML("<h1>"+json[i].fashion+"</h1>");
      }
      }),
     $("#classic").click(function(){
      for(int i = 0;i<json.length;i++){
       document.getElementById("classic-song").innerHTML("<h1>"+json[i].classic+"</h1>");
      }
      }),
     $("#rock").click(function(){
      for(int i = 0;i<json.length;i++){
       document.getElementById("rock-song").innerHTML("<h1>"+json[i].rock+"</h1>");
      }
      }) 
    
    },
    "error":function(xmlhttp,errorText){
     if(xmlhttp.status == "405"){
      alert("请求方式不存在");
     }else if(xmlhttp.status == "404"){
      alert("资源不存在");
     }else if(xmlhttp.status == "500"){
      alert("服务器错误");
     }else{
      alert("产生异常,请联系管理员");
     }
    }
   })
  })
</script>
</head>
<body>
  <input id="fashion" type="submit" value="流行歌曲">
  <div id="fashion-song"></div>
  <input id="classic" type="submit" value="经典歌曲">
  <div id="classic-song"></div>
  <input id="rock" type="submit" value="摇滚歌曲">
  <div id="rock-song"></div>
</body>
</html>

写回答

1回答

好帮手慕阿莹

2019-03-08

1、同学在浏览器端按F12,看看是否是报错:Uncaught SyntaxError: Unexpected identifier  

如果是,是因为,在script中,变量不能用 int i ,而应该用 var i 

http://img.mukewang.com/climg/5c823004000102d706960186.jpg

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

0

0 学习 · 10204 问题

查看课程