1、单击双击触发事件
onclick()
ondbclick()
window.location.href="/home ";
2、绝对路径getPath()
thymeleaf模板的缘故,本地的url不需要加绝对路径,但是丢到服务器就需要,所以平时编程的时候把result设置为“ ”。
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org"></html>
function getPath() {
var pathName = document.location.pathname;
var index = pathName.substr(1).indexOf("/");
var result = pathName.substr(0, index + 1);
// return result;
return "";
}
1.substr 定义和用法
substr() 方法可在字符串中抽取从 start 下标开始的指定数目的字符。
语法
str.substr(startIndex,length)
参数
startIndex (必须):起始下标
length(非必须):截取的长度,如果不写默认截取到末尾
如 var str = “Hello world!”
str.substr(3); 或 str.substr(3,9); 结果都是”lo world!” (别忘了中间的空格~)
2.substring 定义和用法
substring() 方法用于提取字符串中介于两个指定下标之间的字符。
语法
str.substring(startIndex,stopIndex)
参数
start (必须):开始的下标
stop(非必须):结束的下标,比要提取的子串的最后一个字符在 str中的位置多 1如果省略该参数,那么返回的子串会一直到字符串的结尾。
如 var str = “Hello world!”
str.substring(3); 或 str.substring(3,12); 结果都是”lo world!” (别忘了中间的空格~)
str.substring(0,5) 结果是”Hello”
3、不同于jsp的静态html页面显示后台参数
//后台代码,通过前端获取到的参数,post到后台,后台接受处理后,再通过model的addAttribute方法add到前端,前端再通过thymeleaf模板获取。
@RequestMapping(value = "/modify")
public String modify(String applyNumber, Model model) {
try {
MerchantInfo info=merchantInfoService.selectByApplyNumber(applyNumber);
model.addAttribute("merchantInfo",info);
} catch (Exception e) {
e.printStackTrace();
}
return "/page/submit";
}
//前端代码获取,比如input框,或者span的标签等
<input name="confirmChannelNo" id="confirmChannelNo" th:value="${nfo}" class="layui-input">
//再比如,select标签比较特殊,不能直接th:value="${info}",需要用th:text="${info}"
<select name="city" lay-verify="required" id="storeType">
<option th:value="${merchantInfo.storeType}" th:text="${merchantInfo.storeType}"></option>
<option value="同业">同业</option>
<option value="异业">异业</option>
</select>
4、页面加载之前dosomething
window.function(){
var identity = $("#identity").val();
var geographicInfo =document.getElementById("geographicInfo");
//比如获取页面的高宽,然后动态赋值给图片等。
//获取屏幕大小,计算长宽比例,然后修改背景图片大小
function resize(idName){
var widthStr = $("#"+idName).css("width");
var width = parseInt(widthStr.slice(0,widthStr.length-2));
// console.log(width);
var height = $("#"+idName).css("height");
// console.log(height);
$("#"+idName).css("height",height);
}
resize("center_content");//需要获取的页面id
}