选用springboot项目为例,在src/main下创建webapp文件夹,在下面创建HTML页面进行js代码测试
如何生成webapp文件夹? 点击–>创建webapp文件夹
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script type="text/javascript">
//编写一个JS对象
var user={
name:"魏一鹤",
age:23,
sex:"男"
};
//输出一个这个JS对象
console.log(user);//{age: "23",name: "魏一鹤",sex: "男"}
//将JS对象转换为JSON字符串
var json = JSON.stringify(user);
console.log(json)//{"name":"魏一鹤","age":"23","sex":"男"}
//将JSON字符串转换为JS对象
var js=JSON.parse(json);
console.log(js);
</script>
</body>
</html>
趣味代码 扒百度源码
https://sp1.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su#
后面加上wd参数就是我们输入的内容和请求结果
https://sp1.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=123#
和我们在网页搜索框输入动态变化是类似的