jquery设置context type设置
jquery ajax contentType设置
默认get方法没有contentType,post方法的contentType为:application/x-www-form-urlencoded; charset=UTF-8
$.ajax({
type: 'post',
url:'/contentType',
contentType:'application/x-www-form-urlencoded',
data:{
username:'admin',
password:'123123'
},
dataType:'json',
success:function (data) {
}
})
如何利用jquery来向一个元素中添加和移除css类
Jquery使用addClass()与removeClass()来动态的添加或移出一个css类,例如:
1.$(“#para1”).addClass('highlight');添加一个“highlight”css类给id为para1的元素。
2.$(‘#para1’).removeClass(‘'highlight');从id为para1的元素中移出一个‘highlight’css类。具体实例代码如下:<html><head><styletype="text/css">.highlight{background:green;}</style><scripttype="text/javascript"src="jquery-1.
3.2.min.js"></script></head><body><h1>jQueryadd/removecssclassexample</h1><pid="para1">Thisisparagraph1</p><p>Thisisparagraph2</p><p>Thisisparagraph3</p><p>Thisisparagraph4</p><buttonid="addClass">Addhighlight</button><buttonid="removeClass">Removehighlight</button><scripttype="text/javascript">$("#addClass").click(function(){$('#para1').addClass('highlight');});$("#removeClass").click(function(){$('#para1').removeClass('highlight');});</script></body></html>初始的效果:点击addhighlight后的效果图:点击removehighlight后的效果图: