Ajax 页面ajax渲染 js 模板字符串 使用 JS 实现sibling()

jsp 页面ajax渲染 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<table>
<tr id="t1">
<th>图书名称</th>
<th>图书作者</th>
<th>购买时间</th>
<th>图书分类</th>
<th>操作</th>
</tr>






</table>


</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
queryAll();
function del(id) {
	var isok = confirm("确认要删除吗");
	if(isok){
		$.ajax( {
		    "url"            :  "del",                      // 要提交的URL路径
		    "type"         :  "get",                     // 发送请求的方式
		    "data"         :  {"id":id},                      // 要发送到服务器的数据
		    "dataType" :  "text",                   // 指定传输的数据格式
		    "success"  :  function(result) {      // 请求成功后要执行的代码
			   queryAll();
		    	
		    },
		     "error"       :  function() { 
		    	alert("网络正忙");
			     }
		} );
	}else{
		return;
	}
	
}
function  queryAll() {

	$.ajax( {
	    "url"            :  "queryAll",                      // 要提交的URL路径
	    "type"         :  "get",                     // 发送请求的方式
	    "data"         :  {},                      // 要发送到服务器的数据
	    "dataType" :  "json",                   // 指定传输的数据格式
	    "success"  :  function(result) {  // 请求成功后要执行的代码
	    	var temp="";
	    
	    	for ( var bm in result) {
	    		
	    		 temp += `
	    		 <tr>
		    		<td>\${result[bm].name}</td>
		    		<td>\${result[bm].author}</td>
		    		<td>\${result[bm].timeStr}</td>
		    		<td>\${result[bm].typeStr}</td> //属性可不写  底层调用的是它的get方法
		    		<td><a  href="javascript:;" style="text-decoration: none"  onclick="del(\${result[bm].id})">删除</a></td>  
		    		</tr>`
			}
	    	  $("#t1").siblings().remove();
		   $("#t1").after(temp);
	    },
	     "error"       :  function() { 
	    	 // 请求失败后要执行的代码
		     }
	} );
	
	
	
	
	
	
}




</script>


</html>

 

因为是${}会和 EL表达式冲突 需要加上\  转义字符

 

一、使用连接符 + 把想要连接的字符串串起来
let shy = '帅哥'
let a =  '你是' + shy
console.log(a)  // 你是帅哥
1
2
3
二、数组api join拼接
let arr = ['hello','java','script']
let str = arr.join("")
console.log(str) // hellojavascript
// join('--') 这个是可以换的 换--就是用--拼接
1
2
3
4
三、末班字符串 俩 ` 拼接
let a = 'java'
let b = `hello ${a}script`
console.log(b) // hellojavascript
1
2
3
四、使用 js的 concat() 方法连接字符串
concat() 方法用于连接两个或多个数组或者字符串。
该方法不会改变现有的数组,而仅仅会返回被连接的新数组。
字符串就会拼接在一起

let a = ['java']
let b = ['script']

let str = a.concat(b)
console.log(str)  //  ["java", "script"]
1
2
3
4
5
let a = 'a'
let b= 'b'
console.log(a.concat(b)) // ab 

实体类

package entity;

import java.text.SimpleDateFormat;
import java.util.Date;

public class BookManage {
	private Integer Id;
	private String  name;
	private String  author;
	private Date    time;
//	private String    timeStr;  属性可不写  底层调用的是它的get方法
	private Integer type;
//	private String typeStr;
	public String getTypeStr() {
		switch (type) {
		case 1:
			
			return "计算机/软件";
		case 2:
			
			return "小说/文摘";
		case 3:
	
			return "杂项";

			default:
			return "未知";
		}
		
		
		
	}
	public Integer getId() {
		return Id;
	}
	public void setId(Integer id) {
		Id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public Date getTime() {
		return time;
	}
	public void setTime(Date time) {
		this.time = time;
	}
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	public BookManage(Integer id, String name, String author, Date time, Integer type) {
		super();
		Id = id;
		this.name = name;
		this.author = author;
		this.time = time;
		this.type = type;
	}
	public BookManage() {
		super();
		// TODO Auto-generated constructor stub
	}
	@Override
	public String toString() {
		return "BookManage [Id=" + Id + ", name=" + name + ", author=" + author + ", time=" + time + ", type=" + type
				+ "]";
	}
	public String getTimeStr() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String format = simpleDateFormat.format(time);
		
		return format;
	}
	

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kjshuan

点个赞就好啦!!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值