JQ工具函数运用
1.把对象转换为字符串
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="../Scripts/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(function () {
$("button").click(function () {
var option = {
user: "wangqiang",
pass:"123456789"
}
var str = jQuery.param(option);
$("#result").text(str);
})
})
</script>
<title></title>
</head>
<body>
<button>定义序列化字符串</button>
<div id="result"></div>
</body>
</html>
2.处理字符串(去除空格)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="../Scripts/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(function () {
$("button").click(function () {
var str = " ";
alert(str.length);
str = jQuery.trim(str)
alert(str.length);
}) })
</script>
<title></title>
</head>
<body>
<div> <button> 修剪字符串</button>
</div>
</body>
</html>
3.对数组和集合进行迭代
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="../Scripts/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(function () {
var a = [
{ width: 400 },
{ height: 300 }
];
jQuery.each(a,function(name,value)
{
if (name > 0) return false;//只进行一次循环即退出 需要退出each循环,返回一个false就可以了
alert(name+="="+value);
}) })
</script>
<title></title>
</head>
<body> </body>
</html>
4.对数组进行筛选
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="../Scripts/jquery-1.9.1.js"></script>
<script type="text/javascript">
//筛选数组
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
arr = jQuery.grep(arr, function (value, index) {
return value >= 5;
})
alert(arr);
//转换数组
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
arr = jQuery.map(arr, function (elem) {
return elem * 2 > 5 ? elem * 2 : null;
})
alert(arr);
//合并数组
var arr1 = [1, 2, 3, ["a", "b", "c"]];
var arr2 = [4, 5, 6, [7, 8, 9]];
arr3 = jQuery.merge(arr1, arr2);
alert(arr1);
alert(arr1.length);//
alert(arr3);
alert(arr3.length);
</script>
<title></title>
</head>
<body> </body>
</html>
5.检测用户代理
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="../Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript">
$(function () {
var brower = $.browser;
var temp = "";
for (var name in brower)
{
if (brower[name] == true) {
temp += name + "=" + brower[name] + "当前浏览器是:" + name;
}
else { temp += name + "=" + brower[name];
}
}
$("div").html(temp);
})
</script>
<title></title>
</head>
<body>
<div></div>
</body>
</html>
6.判断是否是数组类型
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="../Scripts/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(function () {
var a = [
{width:400},
{height:300}
];
if (jQuery.isArray(a))
alert("变量a是数组"); })
</script>
<title></title>
</head>
<body> </body>
</html>
7.生成数组
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="../Scripts/jquery-1.9.1.js"></script>
<script type="text/javascript">
var arr = jQuery.makeArray($("li").val);
alert(arr);
$("ul").html(arr.reverse()); </script>
<title></title>
<style type="text/css"></style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
</ul>
</body>
</html>
JQ工具函数运用的更多相关文章
- JQ工具函数
在jQuery中,工具函数是指直接依附于jQuery对象,针对jQuery对象本身定义的方法,即全局性的,我们统称为工具函数,或Utilites函数 主要作用于:字符串.数组.对象 API:工具函数 ...
- jQuery源码分析-03扩展工具函数jQuery.extend
// 扩展工具函数 jQuery.extend({ // http://www.w3school.com.cn/jquery/core_noconflict.asp // 释放$的 jQuery 控制 ...
- JQuery中的工具函数总结
前提引入 前提当然也是要引入Jquery啦... <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" typ ...
- 五、jquery使用工具函数
工具函数对应的网址在 http://api.jquery.com/categouy/utilities/ 工具函数处理对象的不同,可以将其分为几大类别:浏览器的检测.数组和对象的操作.字符串的操作 ...
- jQuery工具函数(转)
原文地址:http://www.cnblogs.com/kissdodog/archive/2012/12/27/2835561.html 作者:逆心 ------------------------ ...
- jQuery实用工具函数
1. 什么是工具函数 在jQuery中,工具函数是指直接依附于jQuery对象.针对jquery对象本身定义的说法,即全局性的函数,我们统称为工具函数,或Utilities函数.它们有一个明显的特征, ...
- javascript工具函数
第一部分 JavaScript工具函数 转义特殊字符为html实体 HtmlEncode: function(str){ return str.replace(/&/g, '&') ...
- 读<jQuery 权威指南>[6]--实用工具函数
官方地址:http://api.jquery.com/category/utilities/ 一.数组和对象操作 1. $.each——遍历 $.each(obj,function(param1,pa ...
- AJAX编程-封装ajax工具函数
即 Asynchronous [e'sɪŋkrənəs] Javascript And XML,AJAX 不是一门的新的语言,而是对现有技术的综合利用.本质是在HTTP协议的基础上以异步的方式与服务器 ...
随机推荐
- HCE:Host-based Card Emulation基于Android设备的卡片模拟器
HCE技术支持提供了一个软实现SE的通路,Service实现的方式很多,可以使用文件,使用网络,甚至连接真正的SE.支持HCE的测试手机:目前可以确定使用了NXP PN547作为CLF的NFC手机已经 ...
- hibernate的3种状态
hibernate的三种状态是瞬态.持久态.脱管态 瞬态:新new来的对象称为瞬态. 持久态:处于该状态的对象在数据库中有一条对应的记录,并拥有一个持久标识. 脱管态:当与某持久对象的session关 ...
- SVG 教程
SVG 意为可缩放矢量图形(Scalable Vector Graphics). SVG 使用 XML 格式定义图像. 现在开始学习 SVG! <html> <body> &l ...
- c++编程中的后缀
.a 静态库 (archive) .C.c.cc.cp.cpp.cxx.c++ C++源代码(需要编译预处理) .h C或者C++源代码头文件 .ii C++源代码(不需编译预处理) .o 对象文件 ...
- oauth2认证
using System; using System.Collections.Generic; using System.Security.Cryptography; using System.Con ...
- protobuf使用错误总结
1>HelloWorldScene.obj : error LNK2019: 无法解析的外部符号 "public: virtual __thiscall LoginReqMessage ...
- CSS3实战开发 表单发光特效实战开发
首先,我们先准备好html代码: <!doctype html> <html> <head> <meta charset="utf-8"& ...
- 一台服务器同时搭建IIS和WAMP,利用WAMP 80端口转发
打开wamp 里面的 httpd.conf 文件,找到以下四个语句,取消注释 #LoadModule proxy_module modules/mod_proxy.so -->LoadModul ...
- nide.js(二)文件I/O
文件I/O fs模块的基本用法 node.js中提供一个名为fs的模块来支持I/O操作,fs模块的文件I/O是对标准POSIX函数的简单封装. 1.writeFile函数的基本用法 文件I/O,写入是 ...
- NodeJS下载文件实例
var http = require('http');var express = require('express');var fs=require("fs"); var app ...