常用的jquery函数总结

 

<pre name="code" class="javascript">

 

 

1、表单验证

 

2、$.post

 

function save_project(ctx){
	alert(121);
	/*if(!checkForm()){
		return;
	}*/
	var url="${ctx}/project/ajax/save_project";
	var param=$("#proForm").serialize();
	param=param+"&random="+Math.random();
	alert(param);
	$.post(url,param,function(json){
		if(!json.flag){			
			alert("失败");
		}else{
			alert("成功");
		}
	});
}

 

 

 

 

 

3、$.ajax

 

function doTestJson(ctx){
	alert( $("#proForm").serialize());
    $.ajax({
    	url:ctx+'/project/ajax/save_project',
        type: 'POST', 
        data: $("#proForm").serialize(),
        dataType: 'json',
        contentType:'application/json;charset=UTF-8',        
        success: function(json) { 
            alert(json.result); 
        }
    });
}
//序列化表单元素,返回json数据  
            var params = $("#userForm").serializeArray();  
              
            //也可以把表单之外的元素按照name value的格式存进来  
            //params.push({name:"hello",value:"man"}); 

 

4、form提交

 

第一种:

 

$(function() {
	    
	    $("#tijiao").click(function() { 
	    	if(checkForm()){
		        $("#myForm").ajaxSubmit({
		             url: "${ctx}/teacher/addTeacher.shtml",   // 提交的页面
		             data: $("#myForm").serialize(), // 从表单中获取数据
		             type: "POST",                   // 设置请求类型为"POST",默认为"GET"
		             dataType:"json",
			         success: function(json) {
			            jAlert(json.result, '结果',function(r){
							if(json.flag) {
								window.close();
							}else {
								return;
							}
						});
			 		}
		        	
		        }); 
	        }else{
	        	 jAlert("请检查表单必填项,是否填写", '结果');
	        }
	        return false; 
	    }); 
		
});

$(function(){});这个是必须的。

第二种:

 

//保存所有选中的
		    $("#myForm2").submit(function() {//重点难点
		    	if(true){
			       $(this).ajaxSubmit({
			             url: "${ctx}/courseservices/saveText.shtml",
			             data: $("#myForm2").serialize(),
			             type: "POST",
			             dataType:"json",
				     success: function(json){
				        if(!json.flag){		
						alert('失败');
					}else{
						alert('成功');
					}
				     }
			        	
			        });
		        }
		        return false; 
		    });

 

 

 

 

 

5、jquery全选/取消 checkbox

 

$("#checkall").click(function(){
      if(this.checked){
	$("input[type='checkbox'][name='indexs']").each(function(){this.checked=true;});
      }else{
	$("input[type='checkbox'][name='indexs']").each(function(){this.checked=false;});
      }
}); 

 

 

6、级联选择

 

 

 

/**
 * 组织机构联想查询
 * @param name
 * @param selectId
 * @param deptType 
 */
function getDeptByName(name,selectId,deptType){
	$.ajax({
		url:contextPath+"/public/getDeptByName.shtml",
		type:"post",
		data:{"deptName":$("#"+name).val(),"deptType":deptType,"r":Math.random()},
		dataType:"json",
		success:function(msg){
			$("#"+selectId).empty();
			$('#'+selectId).append("<option value=''>请选择</option>");
			$.each(msg.mapList, function(i, item) {
				$('#' + selectId).append("<option value='" + item.deptId + "'>"+item.deptName+ "</option>");
			});

		}
	
	});
	
}


or

 

 

/** 
 * 场地联动查询 
 * target 目标name
 *  */
function getVenuesByAreaId(areaId,target){
	$.ajax({
		url:contextPath+"/getVenuesByAreaId.shtml",
		type:"post",
		data:{"id":areaId,"r":Math.random()},
		dataType:"json",
		success:function(msg){
			//alert(msg.gtlist.length);
			var option = "";			
				option +="<option value=''>场地</option>";
				for(var i=0;i<msg.mapList.length;i++){
					option += "<option value='"+msg.mapList[i].id+"'>"+msg.mapList[i].name+"</option>";			
			     }	
			$("select[name='"+target+"']").html(option);

		}
	
	});
}

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值