ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

JSP + JQuery作为MVC的前端

2026/8/5 10:24:17 拓冰建站 浏览量
JSP + JQuery作为MVC的前端

1.修改某个元素中的内容

<span class="colorRed"></span>
<tbody id="xxx"></tbody>
  var numEle = document.getElementById("errNum");numEle.innerText = res.length;$(".colorRed").html(errNum); // jquery提供的方法$("#xxx").html('<tr></tr>');

2.jsp中将日期转化为指定的格式

首先需要在jsp页面引入:

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

使用:对应的updatetime在数据库中的类型为datetime

<span><fmt:formatDate value="${basicInfo.updatetime}" type="date" pattern="yyyy-MM-dd HH:mm:ss"/></span>

3.原生的下拉选择框使用与取值

select默认值为x

<select class="" id="unitid" value="x"><option value="x">老式蛋糕奶茶</option><option value="y">台式珍珠奶茶</option>
</select>

option单个取值:

$("#unitid option:selected").val() // jquery的用法

如果希望select的值能够跟着选中状态变化,js中加入:

$(function () {$("#unitid").change(function (){$("#unitid").val($("#unitid option:selected").val()) // jquery的用法})
});

4.当拼接html时,需要给调用的方法传递对象参数报错;拼接两个参数的方法

问题描述:出现onclick([object Object])类似的报错。
使用JSON.stringify(item).replace(/"/g, “'”)转为json字符串传递,对应的函数接收之后会变为对象

spanHtml += '<span οnclick="askErrs(' + JSON.stringify(item).replace(/\"/g, "'") + ',' + startPos + ')">' + paraText.substring(startPos, endPos) + '</span>';
$("#x_" + paraIndex).html(spanHtml);