记录一下Jquery日常使用过程中的一些经验

好记性不如烂笔头

$("p").not("#selected")
$(selector).is(selectorElement,function(index,element))
 $("body").on("click","#customer li",function (event) {
   //事件代码
 });

jq上传文件

{
    // 不修改 Content-Type 属性,使用 FormData 默认的 Content-Type 值
     contentType: false,
     // 不对 FormData 中的数据进行 url 编码,而是将 FormData 数据原样发送到服务器
     processData: false,
}
$.ajax({
	type: "POST",
	url: location.pathname+"?act=uploadsTask",
	data: index.data,
	contentType: false,
	cache: false,
	processData: false,
	datatype: "json",
	beforeSend: function () {
		$("#upload").text("上传..");
	},
	success: function (data) {
		data = JSON.parse(data);
		if (data.code != 1) {
			layer.msg(data.msg, {time: 2000});
		} else {
			layer.close(index.pane);
			$(".button").show();
			$("#modal").hide();
			layer.msg(data.msg, {time: 2000});
		}
	},
	complete: function () {
		$("#upload").text("开始上传");
		$("input[type=file]").val("");
		layer.close(indexs);
	},
	error: function () {
		layer.msg("出错了!", {time: 2000});
	}
});

jq+js总结,基于传统使用思维

  1. 将同一大类的功能放在一个js文件里。
  2. 将文件内所有功能进行分类,封装在不同的对象里。
  3. 用jq把事件和封装的对象事件处理方法进行绑定。
  4. 最终可以避免事件处理和执行代码混乱,造成维护困难,代码阅读性极差。
  5. 这应该是一种编程组装的方法,基于此方法,结合模块化思想。完美

其实最终就是模块化,此处转向require.js