简体   繁体   中英

refresh a specific div on jsp page and not whole page

i want to refresh a div on the basis of input ...here is a sample code:

<%@ page language="java" contentType="text/html; charset=windows-1256"
    pageEncoding="windows-1256"%>
<!DOCTYPE html PUBLIC "-//W3C//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=windows-1256">
</head>
<body>
<input type="button" id="1" value="1" onClick="javaScript:update('1');"/>
<input type="button" id="2" value="2" onClick="javaScript:update('2');"/>
<%
int value=1;
%>
<div id="refresh">
<%=value %>
</div>
<script type="text/javascript">

function update(input)
{
        value=input;
        alert(value);
}

</script>
</body>
</html>

so here is what i want when page loads it will print 1 as value is initialized with 1 but if i click 2 i want that div to print 2 whose value gets updated in update function of java script ...i don't want to refresh whole page just want to refresh that div ...i don't want to use JQUERY.load as it loads the whole page in div i just want to refresh that div

function update(input)
{
        $("#refresh").html(input)
}

That should be all you need

.html() is the jQuery function that changes the innerHTML of an element.

For ajax you can look at the jquery docs here and this is a nice looking example for jQUery + php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM