我的css没有起作用以及一级菜单一行输出,谢谢!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.5.1.js"></script>
<script type="text/javascript">
$(".d1").addClass("yangshi");
$(function(){
$.ajax({
"url" : "/channels/ChannelServlet",
"data" : {"p1":"1"},
"dataType" : "json",
"type" : "get",
"success" : function(json){
console.log(json);
for(var i=0;i<json.length;i++){
var ch=json[i];
$("#choose").append("<option value='"+ch.code+"'>"+ch.name+"</br>"+"</option>");
}
}})
})
</script>
<style type="text/css">
.yangshi{
width:200px;
height:30px;
}
</style>
</head>
<body>
<select class="d1">
<option selected="selected" id="choose"></option>
</select>
<select class="d1">
<option></option>
</select>
</body>
</html>
package com.imooc.channels;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON;
/**
* Servlet implementation class ChannelServlet
*/
@WebServlet("/ChannelServlet")
public class ChannelServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ChannelServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String p1=request.getParameter("p1");
String p2=request.getParameter("p2");
//创建一个list集合
List list=new ArrayList();
if(p1.equals("1")){
list.add(new Channel("major1","物联网"));
list.add(new Channel("major2","网络安全"));
}else if(p1.equals("2")) {
if(p2.equals("major1")) {
list.add(new Channel("class1","物联网19201"));
list.add(new Channel("class2","物联网19202"));
}else if(p2.equals("major2")) {
list.add(new Channel("clas1","网络安全19201"));
list.add(new Channel("clas2","网络安全19202"));
}
}
String josn=JSON.toJSONString(list);
response.setContentType("text/html;charset=UTF-8");
response.getWriter().println(josn);
}
}
package com.imooc.channels;
public class Channel {
private String code;
private String name;
public Channel(String code, String name) {
super();
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
正在回答
同学你好,
1、css没有起到作用是因为代码是从上至下执行的,这里并没有找到属性为d1的,所以这里需将其添加至如下位置处。或将<script>标签内容放在<body>标签下
2、这里只有一级菜单输出是因为二级栏目这里并没有书写相关代码。同学可继续往后学习,在下一章节中老师有讲解
https://class.imooc.com/lesson/892#mid=21931
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星