-
Notifications
You must be signed in to change notification settings - Fork 0
jquery基础
jquery选择分类:
id
class
tag
一些特殊的:
$("a:first")
$("tr:odd")
$("div:visible")
$("p:containts(Life)")选择文本包含Life的p元素
还有一些高级的:
$("[id*='target']")查找id以target为开头的dom节点。
jquery方法和js原生方法的比较,如何注意两者之间的使用,不能混用哦。
jquery的取值和赋值的合并:val(),attr(),html()
<script>
$(function(){
//alert( $('h1').html() ); //取值 : 一组中的第一个
$('h1').html('hello'); //赋值 : 一组中的所有元素
});
</script>
\<h1>hi_1\</h1>
\<h1>hi_2\</h1>
\<h1>hi_3\</h1>
\<h1>hi_4\</h1>
\<h1>hi_5\</h1>
jquery的each()函数的使用,经常与js原生的forEach()函数使用混淆。
jquery工具方法(函数)
$.方法 : 工具方法,原生的JS也可以用
var aLi = document.getElementsByTagName('li');
$.each(aLi,function(index,elements){
elements.innerHTML = index;
});
这里的aLi 就是原生的js。
jquery的事件:独立事件和通用事件
jquery的toggle事件(循环执行函数)
$('input').toggle(function(){
$('div').hide();
},function(){
$('div').show();
});
第一次执行第一个函数,第二次执行第二个函数,toggle可以有更多的函数传入。如:
$('input').toggle(function(){
alert(1);
},function(){
alert(2);
},function(){
alert(3);
})
jquery动画
常见动画效果:fadeIn(),fadeOut(),slideDown(),slideUp()
复杂效果:animate(),stop()
$('div').hover(function(){
$(this).stop().animate({
width : 300,
height : '300px'
});
},function(){
$(this).stop().animate({
width : 200,
height : '200px'
});
});
参考:https://refreshless.com/nouislider/examples/
我需要传一个传参,现在参数是个对象。首先我就会想到这样传参:
$.ajax({
type:"GET",
url:"/send_msg.do",
data:{
content:'电话号码',
recivers:'v_wbgjiang',
way:'1,2',
title:'关键字告警',
emailTemplateId:1,
alertBean:{
domainId:43152,
alertObj:'jiangOBJ',
alertLevel:1,
alertInfo:'匹配结果=[warn]'
// },
//origin:'1',
//useUmgPolicy:"0"
},
dataType:"json",
success:function(data){
console.log(data);
}
});结果请求后台报错了:Request processing failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'alertBean[domainId]' of bean class [com.webank.ims.common.umg.bean.ComSendMsgBean]
改为这样就可以了:
$.ajax({
type:"GET",
url:"http://10.255.4.120:10811/ims_umg_api/send_msg.do",
data:{
content:'电话号码',
recivers:'v_wbgjiang',
way:'1,2',
title:'关键字告警',
emailTemplateId:1,
// alertBean:{
"alertBean.domainId":43152,
"alertBean.alertObj":'jiangOBJ',
"alertBean.alertLevel":1,
"alertBean.alertInfo":'匹配结果'
// },
//origin:'1',
//useUmgPolicy:"0"
},
dataType:"json",
success:function(data){
console.log(data);
}
});$.unique(arr)是去掉数组中的重复值的
$.isEmptyObj(obj)可以判断一个对象是不是null和{}
$.extend可以用来复制对象,并重新new个堆