jQuery使用總結-CorejQuerySelectors選擇器二3/4
生成元素
$(`<img>`,
{
src: `images/little.bear.png`,
alt: `Little Bear`,
title:`I woof in your general direction`,
click: function(){
alert($(this).attr(`title`));
}
})
.css({
cursor: `pointer`,
border: `1px solid black`,
padding: `12px 12px 20px 12px`,
backgroundColor: `white`
})
.appendTo(`body`);
Element properties and attributes
$(`*`).attr(`title`,function(index,previousValue) {
return previousValue + ` I am element ` + index +
` and my name is ` + (this.id || `unset`);
});
This method will run through all elements on the page, modifying the title attribute of each element by appending a string (composed using the index of the element within the DOM and the id attribute of each specific element) to the previous value.
$(`input`).attr(
{ value: “, title: `Please enter a value` }
);
$(“a[href^=`http://`]”).attr(“target”,”_blank”);
First, we select all links with an href attribute starting with http:// (which indicates that the reference is external). Then, we set their target attribute to _blank.
元素的class屬性處理
<div class=”someClass anotherClass yetAnotherClass”></div>
addClass removeClass toggleClass hasClass
元素的css屬性處理
$(“div.expandable”).css(“width”,function(index, currentWidth) {
return currentWidth + 20;
});
.css({
cursor: `pointer`,
border: `1px solid black`,
padding: `12px 12px 20px 12px`,
backgroundColor: `white`
})
元素上的自定義資料
$(“div”).data(“blah”); // undefined
$(“div”).data(“blah”, “hello”); // blah設定為hello
$(“div”).data(“blah”); // hello
$(“div”).data(“blah”, 86); // 設定為86
$(“div”).data(“blah”); // 86
$(“div”).removeData(“blah”); //移除blah
$(“div”).data(“blah”); // undefined
元素的內容
var text = $(`#theList`).text();
函式:html text
文件處理
$("p").append("<b>Hello</b>");
$("p").wrap("<div class=`wrap`></div>");
在“jQuery 1.4.1 Cheat Sheet.chm”文件處理節有例子
主要有:插入、替換、刪除、包裹
Form元素處理
函式Val
$("#single").val("Single2");
$("#multiple").val(["Multiple2", "Multiple3"]);
$("input").val(["check2", "radio1"]);
$(`input:text.items`).val(function() {
return this.value + ` ` + this.className;
});
相關文章
- JQuery知識總結之選擇器jQuery
- jQuery 選擇器彙總-思維導圖-選擇器jQuery
- jQuery原始碼剖析 (二) - 選擇器jQuery原始碼
- jQuery第二章選擇器jQuery
- Jquery基礎筆記二(選擇器)jQuery筆記
- jQuery選擇器jQuery
- jQuery 選擇器jQuery
- jQuery選擇器之層次選擇器jQuery
- jQuery 選擇器效率jQuery
- jQuery選擇器(下)jQuery
- Jquery的選擇器jQuery
- jQuery選擇器介紹:基本選擇器、層次選擇器、過濾選擇器、表單選擇器jQuery
- jquery九大選擇器jQuery
- jquery中的選擇器jQuery
- CSS3新增選擇器(屬性選擇器、結構偽類選擇器、偽元素選擇器)CSSS3
- 4月10日學習筆記——jQuery選擇器筆記jQuery
- jQuery入門-DOM/$/選擇器jQuery
- 關於jQuery中的選擇器jQuery
- 初學jQuery(表單選擇器)jQuery
- jQuery的基礎操作——選擇器jQuery
- jQuery基本篩選選擇器使用指南jQuery
- 使用json和jquery級聯選擇JSONjQuery
- css中:not()選擇器和jQuery中.not()方法CSSjQuery
- jQuery 原始碼學習 (六) 選擇器jQuery原始碼
- JQuery基礎28_選擇器2jQuery
- jQuery基礎——樣式篇 (選擇器)jQuery
- CSS3選擇器02—CSS3部分選擇器CSSS3
- JQuery控制radio選中和不選中方法總結jQuery
- 如何選擇jquery版本jQuery
- 特徵選擇技術總結特徵
- jquery九大選擇器的用法舉例jQuery
- HTML DOM querySelectorAll() 代替 jquery的 $('') CSS選擇器HTMLjQueryCSS
- switch選擇結構使用
- JavaScript(二):選擇、迴圈結構JavaScript
- jquery總結jQuery
- 01、CSS3-選擇器CSSS3
- 002---選擇器(標籤選擇器、類選擇器、id選擇器、偽類選擇器、萬用字元選擇器)字元
- Vue+Element 單選模式下Cascader級聯選擇器使用總結Vue模式
- 不是吧!! ! jQuery選擇器,你要的都在這!!!jQuery