JavaScript与jQuery
为什么jQuery中到处有$
来源:Why does JQuery have dollar signs everywhere?
因为$是jQuery的别名
// These are the same barring your using noConflict (more below)
var divs = $("div"); // Find all divs
var divs = jQuery("div"); // Also find all divs, because
console.log($ === jQuery); // "true"就是简称
jQuery ajax POST 例子详解
function test(){
$.ajax({
//提交数据的类型 POST GET
type:"POST",
//提交的网址
url:"testLogin.aspx",
//提交的数据
data:{Name:"sanmao",Password:"sanmaoword"},
//返回数据的格式
datatype: "html",//"xml", "html", "script", "json", "jsonp", "text".
//在请求之前调用的函数
beforeSend:function(){$("#msg").html("logining");},
//成功返回之后调用的函数
success:function(data){
$("#msg").html(decodeURI(data));
} ,
//调用执行后调用的函数
complete: function(XMLHttpRequest, textStatus){
alert(XMLHttpRequest.responseText);
alert(textStatus);
//HideLoading();
},
//调用出错执行的函数
error: function(){
//请求出错处理
}
});
}对于datatype来说,因为之前不是很理解,所以导致回调函数success总是失败。所以这里再次强调一下
参考资料:第三篇:jquery ajax POST 例子详解
jQuery change child text
<td class="v3">
<a href="somelink">text to change</a>
</td> 然后添加JQuery,$("td.v3").children("a").text("new text");
来源:https://stackoverflow.com/questions/7415292/jquery-change-child-text/7415413
jquery获取第几个元素的方法
使用jquery时经常会遇到,选择器选择一组元素后,需要在这组元素中找到第几个元素。jquery中使用eq()方法找到第几个元素或第N个元素,eq()选择器选取带有指定index值的元素,index值从0开始,所有第一个元素的index值是0(不是1),经常与其他元素/选择器一起使用,来选择指定的组中特定序号的元素。例如:
$(id).children().eq(1).children().eq(1)参考资料:jquery获取第几个元素的方法总结
评论已关闭