jQuery学习笔记

这是一篇关于jQuery的学习笔记,涵盖了选择器的使用、元素的添加、删除和修改,包括标签属性、类属性和样式属性的操作。还讨论了查询、事件处理以及网络请求,如文件上传的示例。此外,提到了一些附加资源,如toggle元素操作和jQuery的deferred对象详细解析。
摘要由CSDN通过智能技术生成

jQuery Study Notes

  • kagula
  • January 15, 2021

Selector

$("#myid")
$("div#myid")
$(".myClassName")
$("#mainTable tbody") //tbody is a html tag under the mainTable.


Add

$("#warning_parameter_setting").append("<span class=\"selected\"></span>");
var inputchange='<input id="inptchange" type="hidden">';
$("body").before(inputchange);//insert the content at the front of body.


Delete

$("span.selected").remove();
$("#sideMenu").children(".nav-item").removeClass("active open");


Modify

//<span id="spanLoginName" name="spanLoginName">  ...登陆中... </span>
$("span#spanLoginName").html(g_user.loginName);//suggest using text method.
$("span#spanDevicePort").html('...');
$("#mainTable tbody").html("");//set empty value
$("#mainTable tbody").text("");//reserved characters will be escaped.
$("#inptchange").val(myVal);//assignment a value.

Tag’s attribution

$("img").attr("width","180");
$(".progress-bar").width(percentComplete + '%');
$('#button').attr('disabled',"true"); //add disabled attribution.
...
$("#id").attr("readonly":"readonly"); //$("#ID").attr({ readonly: 'true' });
...
$("#imgId").attr('src',path); 
...
$('#button').removeAttr("disabled");
...
$("#id").removeAttr("readonly");

Tag’s class attribution

$("#warning_parameter_setting").addClass("active open");//both active and open are class name.
//<button type="button" class="btn red-mint display-hide" id="btnClear">删除线条</button>
... ...
$("#btnClear").removeClass("display-hide");

Tag’s style attribution

$("div#allMap").css("margin-top","30px");//add margin-top style
$("div#kagula_alert").css("display", "block");//add display style
$('#test').css('display', null);//remove display style
$('#test').css('display', '');//remove display style


Query

var username=$("#username").val();
$.each(data.children, function(index, el){
	eachChildren(el, 0);
})


Event

$("span.selected").remove();
//input元素  input propertychange 事件的绑定
$("#inptchange").bind("input propertychange",function () {
//...
});
$("#inptchange").trigger("input"); //fire out the input event.
$("#fileInput").change(function(){
    //...
});


Network

var data={userName:username,password:password};
	
var selectValue = $("#selectDevicePort").val();
var arr=selectValue.split(",");
var data={deviceIndex:arr[0],port:arr[1]};
console.log('updateMap(), data=' + JSON.stringify(data));
//post json string to HTTP server.
$.post('/queryDeviceMapInfo.do', 'data='+JSON.stringify(data),function (objRes) {
    //返回的JSON字符串自动会转为JSON对象
    if(objRes.code&&objRes.code=="0")
    {
       	//... ...
    }
    else
    {
        console.log("get map info failed.");
    }
});
var jsonReq={"loginname":value.account,"password":value.myPassword,"idGroupInfo":idGroupInfo};
$.ajax({
    type: "POST",
    contentType:"application/json",
    url: "DAS2017/user/add.do",
    data: JSON.stringify(jsonReq),
    success: function (data) {
        if(data.code==0)
        {
            console.log("如果添加用户成功,刷新列表。");
        }
        else {
            console.log("如果添加用户失败,弹出错误提示。");
        }
    },
    eror: function (data) {
        console.log(data);
    }
});

The previous code could be corresponding with the below

@RequestMapping(value = "/saveEdit.do", 
		method = RequestMethod.POST, 
		consumes = "application/json")
@ResponseBody
public Object saveEdit(@RequestBody UserInfo ui) {
	RetMsg rm = new RetMsg();
    //... ...
	return rm;
}//function   


File upload example

  • Demo_fileUpload.htm is a standalone html file, can be find at https://github.com/kagula/webcc20200813/tree/master/htmlRoot

Appendix

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kagula086

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值