javascript - refresh a specific div on jsp page and not whole page - Stack Overflow

i want to refresh a div on the basis of input ...here is a sample code:<%@ page language="java&

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" ".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

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/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

Share Improve this question asked Apr 10, 2013 at 2:19 user2137186user2137186 8376 gold badges23 silver badges39 bronze badges 1
  • 1 (OT) why not encode in UTF8 ? – Roko C. Buljan Commented Apr 10, 2013 at 2:21
Add a ment  | 

1 Answer 1

Reset to default 2
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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744868543a4598119.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信