http://jonsion.iteye.com/blog/552921
<script type="text/javascript">
$(document).ready(function() {
//$("#pb1").progressBar();
//$("#pb2").progressBar({ barImage: 'images/progressbg_yellow.gif'} );
//$("#pb3").progressBar({ barImage: 'images/progressbg_orange.gif', showText: false} );
//$("#pb4").progressBar(65, { showText: false, barImage: 'images/progressbg_red.gif'} );
//$(".pb5").progressBar({ max: 2000, textFormat: 'fraction', callback: function(data) { if (data.running_value == data.value) { alert("Callback example: Target reached!"); } }} );
//$("#uploadprogressbar").progressBar();
initcheckbox();
clickEvent();
});
function initcheckbox(){
$.getJSON("http://localhost:8088/JQuery/servlet/DataJson",callbackFun);
}
function callbackFun(data){
if(null!=data){
for(var i=0;i<data.listData.length;i++){
$("#testcheck").append("<div>"+"<input type='checkbox' value='"+ data.listData[i] +"'> " + data.listData[i]+"</div>");
}
}
}
function clickEvent(){
//alert("000000000");
$("#testbutton").click(getCheckBoxValue);
}
function getCheckBoxValue(){
var checkStr = "";
$("div[id=testcheck] input[type=checkbox][checked]").each(function(){
//alert($(this).val());
if(""!=checkStr){
checkStr = checkStr + "," + $(this).val();
}else{
checkStr = $(this).val();
}
});
alert("checkStr==========="+checkStr);
$.getJSON("http://localhost:8088/JQuery/servlet/CopyOfDataJson?testvalue="+checkStr,function(data){alert("it is ok");});
}
</script>
本文介绍了一个使用 jQuery 进行 JSON 数据交互的例子。通过获取服务器上的数据并将其用于动态生成复选框列表,之后再将用户选择的数据发送回服务器进行处理。文中详细展示了如何初始化复选框列表、为按钮绑定点击事件以及发送 JSON 数据到服务器。
5178

被折叠的 条评论
为什么被折叠?



