編輯時,已存在的複選框,預設被勾選
阿新 • • 發佈:2019-02-20
<%@ 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 PUBLIC "-//W 3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > < html > < head > < meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" > < title > Insert title here </ title > </ head > < body > < c:set var = "in" value = "1,5" /> <!-- 已存在複選框 --> < c:forEach var = "i" begin = "1" end = "5" > < input id = "name ${i} " type = "checkbox" /> name${i} <!-- 複選框 --> </ c:forEach > < br /> < c:forEach var = "i" begin = "1" end = "5" > <!-- 如果預設複選框中的值在 複選框中,就被選中 --> < c:forTokens items = " ${in}" delims = "," var = "name" > < c:choose > < c:when test ="${name==i}"> < script type = "text/javascript" > document . getElementById ( "name${i}" ). checked = true ; </ script > </ c:when > </ c:choose > </ c:forTokens > </ c:forEach > </ body > </ html >