


Summary of jQuery common operation implementation methods and common function methods_jquery
jQuery 常见操作实现方式
$("标签名") //取html元素 document.getElementsByTagName("")
$("#ID") //取单个控件document.getElementById("")
$("div #ID") //取某个控件中 控件
$("#ID #ID") // 通过控件ID取其中的控件
$("标签.class样式名") //通过class来取控件
$("#ID").val(); //取value值
$("#ID").val(""); //赋值
$("#ID").hide(); //隐藏
$("#ID").show(); //显示
$("#ID").text(); //相当于取innerText
$("#ID").text(""); //相当于innerText=""
$("#ID").html(); //相当于取innerHTML
$("#ID").html(""); //相当于innerHTML=""
$("#ID").css("属性","值") //添加CSS样式
$("form#表单id").find("#所找控件id").end() //遍历表单
$("#ID").load("*.html") //载入一个文件
例如:
$("form#frmMain").find("#ne").css("border", "1px solid #0f0").end() // end()返回表单
.find("#chenes").css("border-top","3px dotted #00f").end()
$.ajax({ url: "Result.aspx", //数据请求页面的url
type:"get", //数据传递方式(get或post)
dataType:"html", //期待数据返回的数据格式(例如 "xml", "html", "script",或 "json")
data: "chen=h", //传递数据的参数字符串,只适合get方式
timeout:3000, //设置时间延迟请求的时间
success:function(msg)//当请求成功时触发函数
{
$("#stats").text(msg);
},
error:function(msg) //当请求失败时触发的函数
{
$("#stats").text(msg);
}
});
$(document).ready(function(){});
$("#description").mouseover(function(){});
//ajax方法
$.get( "Result.aspx", //数据请求页面的url
{ chen: "测试",age:"25"}, //传递数据的参数字符串
function(data){ alert("Data Loaded: " + data); } //触发后的函数
);
});
});
//取得下拉选单的选取值
$(#testSelect option:selected').text(); //取文本值
或$("#testSelect").find('option:selected').text();
或$("#testSelect").val();
jQuery中常用的函数方法总结
事件处理
ready(fn)
代码:
$(document).ready(function(){
// Your code here...
});
作用:它可以极大地提高web应用程序的响应速度。通过使用这个方法,可以在DOM载入就绪能够读取并操纵时立即调用你所绑定的函数,而99.99%的JavaScript函数都需要在那一刻执行。
bind(type,[data],fn)
代码:
$("p").bind("click", function(){
alert( $(this).text() );
});
作用:为每一个匹配元素的特定事件(像click)绑定一个事件处理器函数。起到事件监听的作用。
toggle(fn,fn)
代码:
$("td").toggle(
function () {
$(this).addClass("selected");
},
function () {
$(this).removeClass("selected");
}
);
作用:每次点击时切换要调用的函数。如果点击了一个匹配的元素,则触发指定的第一个函数,当再次点击同一元素时,则触发指定的第二个函数。挺有趣的一个函数,在动态实现某些功能的时候可能会用到。
(像click(),focus(),keydown()这样的事件这里就不提了,那些都是开发中比较常用到的。)
外观效果
addClass(class)和removeClass(class)
代码:
$(".stripe tr").mouseover(function(){
$(this).addClass("over");}).mouseout(function(){
$(this).removeClass("over");})
});
也可以写成:
$(".stripe tr").mouseover(function() { $(this).addClass("over") });
$(".stripe tr").mouseout(function() { $(this).removeClass("over") });
作用:为指定的元素添加或移除样式,从而实现动态的样式效果,上面的实例中实现鼠标移动双色表格的代码。
css(name,value)
代码:
$("p").css("color","red");
作用:很简单,就是在匹配的元素中,设置一个样式属性的值。这个个人感觉和上面的addClass(class)有点类似。
slide(),hide(),fadeIn(), fadeout(), slideUp() ,slideDown()
代码:
$("#btnShow").bind("click",function(event){ $("#divMsg").show() });
$("#btnHide").bind("click",function(evnet){ $("#divMsg").hide() });
作用:jQuery中提供的比较常用的几个动态效果的函数。还可以添加参数:show(speed,[callback])以优雅的动画显示所有匹配的元素,并在显示完成后可选地触发一个回调函数。
animate(params[,duration[,easing[,callback]]])
作用:制作动画效果用到的函数,功能非常的强大,可以连续使用此函数。
查找筛选
map(callback)
HTML 代码:
Values:
jQuery 代码:
$("#results").append( "" + $("form").serialize() + "" );
作用:序列化表格内容为字符串。用于 Ajax 请求。
工具
jQuery.each(obj,callback)
代码:
$.each( [0,1,2], function(i, n){
alert( "Item #" + i + ": " + n );
});//遍历数组
$.each( { name: "John", lang: "JS" }, function(i, n){
alert( "Name: " + i + ", Value: " + n );//遍历对象
});
作用:通用例遍方法,可用于例遍对象和数组。
jQuery.makeArray(obj)
HTML 代码:
jQuery code:
var arr = jQuery.makeArray(document.getElementsByTagName("div"));
Result:
Fourth
Third
Second
First
Function: Convert array-like objects into array objects. Allows us to flexibly convert between arrays and objects.
jQuery.trim(str)
Function: This should be familiar to everyone, it is to remove the spaces at the beginning and end of the string.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The pandas library is a commonly used data processing and analysis tool in Python. It provides a wealth of functions and methods that can easily complete data import, cleaning, processing, analysis and visualization. This article will introduce a quick start guide to commonly used functions in the pandas library, with specific code examples. The data import pandas library can easily import data files in various formats through functions such as read_csv and read_excel. Here is a sample code: importpandas

As a programming language widely used in Internet application development, PHP has become one of the most popular programming languages in the world. As a very influential code hosting platform, GitHub has also attracted the attention of more and more PHP programmers. In the process of using GitHub for PHP programming, there are some common operations and techniques that need to be mastered. The following article will introduce some key GitHub operations to help PHP programmers better use GitHub for development. Create a repository in Git

The Numpy library is one of the most commonly used data processing libraries in Python. It is widely loved by data analysts for its efficient and convenient operation methods. In the Numpy library, there are many commonly used functions that can help us complete data processing tasks quickly and efficiently. This article will introduce some commonly used Numpy functions, and provide code examples and practical application scenarios so that readers can get started with the Numpy library faster. 1. Create an array numpy.array function prototype: numpy.array(obj

Explore the Go language standard library: Detailed explanation of common functions and data structures Introduction: Since its birth, the Go language has attracted the attention of many developers with its simplicity, efficiency, and concurrency. As a modern programming language, the Go language provides a wealth of functions and data structures in its standard library to help developers quickly build high-performance, reliable applications. This article will explore in detail some commonly used functions and data structures in the Go language standard library, and deepen understanding through specific code examples. 1. strings package: string processing function G

PHP is a widely used open source programming language that is widely used in the field of web development. In web development, file operation is an essential part, so it is very important to be proficient in PHP's file operation functions. In this article, we will introduce some functions commonly used in PHP file operations. fopen() The fopen() function is used to open a file or URL and returns the file pointer. It has two parameters: file name and opening method. The opening mode can be "r" (read-only mode), "w" (write mode), "a"

Commonly used functions in the pandas library include: 1. read_csv() and read_excel() functions; 2. head() and tail() functions; 3. info() function; 4. describe() function, etc. Detailed introduction: 1. read_csv() and read_excel() functions. These two functions are used to read data from CSV and Excel files. They can read the data into data frame objects to facilitate further data analysis; 2. head () and tail() functions, etc.

Image processing is a very important topic in PHP programming. With the development of web applications, more and more websites need to use images to attract users' attention. Therefore, it is very important for PHP developers to master some common image processing operations. This article will introduce some common image processing operations for reference by PHP developers. 1. Image scaling Image scaling is one of the most common operations in image processing. PHP provides two methods to resize images: ImageCopyResample()

As an open source statically typed programming language, Go language has a rich standard library and powerful functions. In the Go language, there are many commonly used functions and methods that can help us simplify the code and improve programming efficiency. The following will introduce several commonly used functions in the Go language and give specific code examples. 1. The Printf function in the fmt package. The fmt package is a standard package for formatting input and output in the Go language. The Printf function in it can output the content to the standard output stream according to the format string. Below is a
