這樣:
成都創(chuàng)新互聯(lián)公司專注于萊陽網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供萊陽營銷型網(wǎng)站建設(shè),萊陽網(wǎng)站制作、萊陽網(wǎng)頁設(shè)計(jì)、萊陽網(wǎng)站官網(wǎng)定制、小程序設(shè)計(jì)服務(wù),打造萊陽網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供萊陽網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
ul class="parent1"
lia href="#" id="item1"jquery獲取父節(jié)點(diǎn)/a/li
lia href="#"jquery獲取父元素/a/li
/ul
擴(kuò)展資料:
注意事項(xiàng)
parent是指取得一個(gè)包含著所有匹配元素的唯一父元素的元素集合。
parents則是取得一個(gè)包含著所有匹配元素的祖先元素的元素集合(不包含根元素)。可以通過一個(gè)可選的表達(dá)式進(jìn)行篩選。
可以看出parent的取值很明確,就是當(dāng)前元素的父元素;parents則是當(dāng)前元素的祖先元素。
div id='div1'
div id='div2'p/p
/divdiv id='div3' class='a'p/p/div
div id='div4'p/p/div
/div
JQuery讀書筆記--JQuery-Form中的AjaxForm和AjaxSubmit的區(qū)別
JQuery中的AjaxForm和AjaxSubmit使用差不多功能也差不多。很容易誤解。
按照作者的解釋:
AjaxForm
ajaxForm不能提交表單。在document的ready函數(shù)中,使用ajaxForm來為AJAX提交表單進(jìn)行準(zhǔn)備。提交動作必須由submit開始
ajaxSubmit
馬上由AJAX來提交表單。你可以在任何情況下進(jìn)行該項(xiàng)提交。
option的參數(shù)
var options = {
target: '#output1', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse // post-submit callback
// other available options:
//url: url // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
// $.ajax options can be used here too, for example:
//timeout: 3000
};
示例代碼摘自:
ajaxForm
The following code controls the HTML form beneath it. It uses ajaxForm to bind the form and demonstrates how to use pre- and post-submit callbacks
// prepare the form when the DOM is ready
$(document).ready(function() {
var options = {
target: '#output1', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse // post-submit callback
// other available options:
//url: url // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
// $.ajax options can be used here too, for example:
//timeout: 3000
};
// bind form using 'ajaxForm'
$('#myForm1').ajaxForm(options);
});
// pre-submit callback
function showRequest(formData, jqForm, options) {
// formData is an array; here we use $.param to convert it to a string to display it
// but the form plugin does this for you automatically when it submits the data
var queryString = $.param(formData);
// jqForm is a jQuery object encapsulating the form element. To access the
// DOM element for the form do this:
// var formElement = jqForm[0];
alert('About to submit: \n\n' + queryString);
// here we could return false to prevent the form from being submitted;
// returning anything other than false will allow the form submit to continue
return true;
}
// post-submit callback
function showResponse(responseText, statusText) {
// for normal html responses, the first argument to the success callback
// is the XMLHttpRequest object's responseText property
// if the ajaxForm method was passed an Options Object with the dataType
// property set to 'xml' then the first argument to the success callback
// is the XMLHttpRequest object's responseXML property
// if the ajaxForm method was passed an Options Object with the dataType
// property set to 'json' then the first argument to the success callback
// is the json data object returned by the server
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
}
ajaxSubmit
The following code controls the HTML form beneath it. It uses ajaxSubmit to submit the form.
// prepare the form when the DOM is ready
$(document).ready(function() {
var options = {
target: '#output2', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse // post-submit callback
// other available options:
//url: url // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
// $.ajax options can be used here too, for example:
//timeout: 3000
};
// bind to the form's submit event
$('#myForm2').submit(function() {
// inside event callbacks 'this' is the DOM element so we first
// wrap it in a jQuery object and then invoke ajaxSubmit
$(this).ajaxSubmit(options);
// !!! Important !!!
// always return false to prevent standard browser submit and page navigation
return false;
});
});
// pre-submit callback
function showRequest(formData, jqForm, options) {
// formData is an array; here we use $.param to convert it to a string to display it
// but the form plugin does this for you automatically when it submits the data
var queryString = $.param(formData);
// jqForm is a jQuery object encapsulating the form element. To access the
// DOM element for the form do this:
// var formElement = jqForm[0];
alert('About to submit: \n\n' + queryString);
// here we could return false to prevent the form from being submitted;
// returning anything other than false will allow the form submit to continue
return true;
}
// post-submit callback
function showResponse(responseText, statusText) {
// for normal html responses, the first argument to the success callback
// is the XMLHttpRequest object's responseText property
// if the ajaxSubmit method was passed an Options Object with the dataType
// property set to 'xml' then the first argument to the success callback
// is the XMLHttpRequest object's responseXML property
// if the ajaxSubmit method was passed an Options Object with the dataType
// property set to 'json' then the first argument to the success callback
// is the json data object returned by the server
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
}
可以看張曉菲的《鋒利的jQuery》,重點(diǎn)是自己理解函數(shù)用法并自行實(shí)現(xiàn)一些常用的效果。
如果需要快速查閱可以用這個(gè)api,每個(gè)函數(shù)都附有簡單的示例: (注:這個(gè)jQuery庫的版本不是最新的delegate等函數(shù)在這兒查不到。歡迎補(bǔ)充別的api~)
jQuery側(cè)重點(diǎn)就是選擇器和基本的DOM操作,還有一些動畫操作,但是js中非DOM操作的部分基本沒有涉及。
其實(shí)jQuery的門檻很低,我在看jQuery的時(shí)候?qū)υ鷍s的東西也知之甚少,在看的過程中遇到不會的多求助搜索引擎,多嘗試,當(dāng)然最好做一下筆記。
測試代碼推薦直接在jsfiddle上測試,左側(cè)你可以自行選擇需要的jQuery庫版本:
//=======================
有一點(diǎn)需要注意,jQuery只是工具,jQuery學(xué)的再好也無法替代原生的js,比如jQuery翻遍了你也不會知道
JavaScript語言中共有幾種基本類型
什么是原型
什么是閉包
什么是原型鏈,作用域鏈
js只有函數(shù)作用域,沒有塊作用域該怎么理解
之于上面的問題,需要再去閱讀js的基礎(chǔ)書籍:《JavaScript權(quán)威指南》,《JavaScript高級程序設(shè)計(jì)》,《JavaScript語言精粹》等
獲取 checkbox的 選中個(gè)數(shù)可以直接使用如下jquery語法$("input[type='checkbox']:checked").length;
示例如下:
創(chuàng)建Html代碼及css樣式
div?
input?type="checkbox"?name="fruit"?apple
input?type="checkbox"?name="fruit"?orange
input?type="checkbox"?name="fruit"?banana
input?type="checkbox"?name="fruit"?watermelonbr
input?type="button"?value="I?like?these?fruit!"
/div
div{width:500px;padding:20px;border:4px?solid?#ebcbbe;}
input{margin:10px?5px;}
jquery代碼
$(function(){
$("input[type='button']").click(function()?{
alert($("input[type='checkbox']:checked").length);
});
})
效果