最近发生在我的网页上,即使是jsp页面元素已经在那里,$("#elementId").change()
不起作用,但$(document).on("change" "elementId"
呢。看起来像页面document
正在懒洋洋地准备好,因此页面元素上的直接事件处理程序不会被添加。任何提示?
ps:我说的元素不是动态生成的。
JSP
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/receipt.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/myCss.css" >
<title>Generate Report</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
</head>
<body>
<form:form action="getReceipt.html" commandName="viewQuote">
<div class="main_div">
<div>
<table>
<tr><td valign="top" align="left">
Res Number
</td>
<td valign="top" align="left" >
<input id="reservatnNo" type="text" name="reservatnNo" value="">
</td>
</tr>
</table>
</div>
<div>
<table>
<tr><td>
<button id="generateReportButton" type="submit">
Submit Form
</button>
</td>
</tr>
</table>
</div>
</div>
</form:form>
</body>
的Javascript
$(document).ready(function() {
jQuery.ajaxSettings.traditional = true;
});
$(document).on("change", "#reservatnNo", function(event) {
//$('#reservatnNo').change(function(){
alert("changeddd");
});
你能在这里分享你的代码吗? –
动态加载'#elementId'。 –
@RajaprabhuAravindasamy不,不像我说的那样动态。我只是使用锚链接从以前的网页调用网页。 – user2918640