教程
jQuery中hide()方法用法实例 jQuery中slideUp()方法用法分析 jQuery中fadeOut()方法用法实例 jQuery中animate()方法用法实例 jQuery中width()方法用法实例 jQuery中height()方法用法实例 jQuery中val()方法用法实例 jQuery中html()方法用法实例 jQuery中append()方法用法实例 jQuery中prepend()方法用法实例 jQuery中after()方法用法实例 jQuery中before()方法用法实例 jQuery中replaceWith()方法用法实例 jQuery中remove()方法用法实例 jQuery中detach()方法用法实例 jQuery中click事件用法实例 jQuery中focus事件用法实例 jQuery中mouseover事件用法实例 jQuery中change事件用法实例 jQuery中ajax的load()方法用法实例 jQuery中ajax的get()方法用法实例 jQuery中ajax的post()方法用法实例 jQuery中的jQuery()方法用法分析 jQuery.holdReady()方法用法实例 jQuery中each()方法用法实例 jQuery中size()方法用法实例 jQuery对象的length属性用法实例 jQuery对象的selector属性用法实例 jQuery的context属性用法实例 jQuery中get()方法用法实例 jQuery中index()方法用法实例 jQuery中data()方法用法实例 jQuery中removeData()方法用法实例 jQuery中queue()方法用法实例 jQuery中dequeue()方法用法实例 jQuery中clearQueue()方法用法实例 jQuery中element选择器用法实例 jQuery中:eq()选择器用法实例 jQuery中:gt选择器用法实例 jQuery中:lt选择器用法实例 jQuery中:header选择器用法实例 jQuery中:animated选择器用法实例 jQuery中:first选择器用法实例 jQuery中:last选择器用法实例 jQuery中:not选择器用法实例 jQuery中:focus选择器用法实例 jQuery中:contains选择器用法实例 jQuery中:empty选择器用法实例 jQuery中:has选择器用法实例 jQuery中:hidden选择器用法实例 jQuery中:visible选择器用法实例 jQuery中[attribute]选择器用法实例 jQuery中[attribute!=value]选择器用法实例 jQuery中[attribute=value]选择器用法实例 jQuery中[attribute^=value]选择器用法实例 jQuery中[attribute*=value]选择器用法实例 jQuery中:first-child选择器用法实例 jQuery中:nth-child选择器用法实例 jQuery中:last-child选择器用法实例 jQuery中:only-child选择器用法实例 jQuery中:input选择器用法实例 jQuery中:text选择器用法实例 jQuery中:password选择器用法实例 jQuery中:radio选择器用法实例 jQuery中:checkbox选择器用法实例 jQuery中:submit选择器用法实例 jQuery中:image选择器用法实例 jQuery中:reset选择器用法实例 jQuery中:button选择器用法实例 jQuery中:file选择器用法实例 jQuery中:enabled选择器用法实例 jQuery中:disabled选择器用法实例 jQuery中:checked选择器用法实例 jQuery中:selected选择器用法实例 jQuery中attr()方法用法实例 jQuery中removeAttr()方法用法实例 jQuery中prop()方法用法实例 jQuery中removeProp()方法用法实例 jQuery中addClass()方法用法实例 jQuery中removeClass()方法用法实例 jQuery中toggleClass()方法用法实例 jQuery中eq()方法用法实例 jQuery中first()方法用法实例 jQuery中last()方法用法实例 jQuery中hasClass()方法用法实例 jQuery中filter()方法用法实例 jQuery中is()方法用法实例 jQuery中map()方法用法实例 jQuery中has()方法用法实例 jQuery中not()方法用法实例 jQuery中slice()方法用法实例 jQuery中children()方法用法实例 jQuery中closest()函数用法实例 jQuery中find()方法用法实例 jQuery中next()方法用法实例 jQuery中nextAll()方法用法实例 jQuery中nextUntil()方法用法实例 jQuery中parent()方法用法实例 jQuery中parents()方法用法实例 jQuery中parentsUntil()方法用法实例 jQuery中prev()方法用法实例 jQuery中prevAll()方法用法实例 jQuery中prevUntil()方法用法实例 jQuery中siblings()方法用法实例 jQuery中add()方法用法实例 jQuery中andSelf()方法用法实例 jQuery中contents()方法用法实例 jQuery中end()方法用法实例 jQuery中append()方法用法实例 jQuery中appendTo()方法用法实例 jQuery中prependTo()方法用法实例 jQuery中insertAfter()方法用法实例 jQuery中insertBefore()方法用法实例 jquery中one()方法的用法实例 jquery事件preventDefault()方法用法实例 jQuery中unwrap()方法用法实例 jQuery中wrapAll()方法用法实例 jQuery中wrapInner()方法用法实例 jQuery中replaceAll()方法用法实例 jQuery中empty()方法用法实例 jQuery中clone()方法用法实例 jQuery中offset()方法用法实例 jQuery中position()方法用法实例 jQuery中scrollTop()方法用法实例 jQuery中scrollLeft()方法用法实例 jQuery中innerHeight()方法用法实例 jQuery中innerWidth()方法用法实例 jQuery中outerHeight()方法用法实例 jQuery中outerWidth()方法用法实例 jQuery中offsetParent()方法用法实例 jQuery中ready事件用法实例 jQuery中on()方法用法实例 jQuery中bind()方法用法实例 jQuery的one()方法用法实例 jQuery中trigger()方法用法实例 jQuery中triggerHandler()方法用法实例 jQuery中unbind()方法用法实例 jQuery中live()方法用法实例 jQuery中die()方法用法实例 jQuery中delegate()方法用法实例 Jquery中find与each方法用法实例 jquery中change()用法实例分析 jquery中filter方法用法实例分析 JQuery中serialize()用法实例分析 jQuery中noConflict()用法实例分析 JQuery中extend的用法实例分析 jQuery中$.extend()用法实例

发布于 2016-10-28 22:58:17 | 133 次阅读 | 评论: 0 | 来源: 网友投递

这篇文章主要介绍了jQuery中的jQuery()方法用法,以实例形式较为详细的分析jQuery()方法的四种常见语法结构与用法技巧,具有一定的参考借鉴价值,需要的朋友可以参考下

本文实例讲述了jQuery中的jQuery()方法用法。分享给大家供大家参考。具体如下:

jQuery()方法的定义和用法:
此方法可以接受一组选择器,用于匹配相应的元素。例如:

jQuery("div")

在实际应用中,一般用$定义jQuery,其实$就是jQuery的简写,比如$("li")可以写成jQuery("li")。
jQuery的核心功能都是通过此方法实现的,或者说以某种方式使用此方法实现。下面就详细介绍一下次方法的用法。
语法结构一:
当jQuery()方法没有任何参数的时候,会返回一个空jQuery对象。

jQuery()

实例代码:



<!DOCTYPE HTML>

<html>

<head>

<meta charset="utf-8"/>

<meta name="author" content="http://www.phperz.com/" />

<title>jQuery()函数-phperz</title>

<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>

<script type="text/javascript">

$(document).ready(function(){

  $("button").click(function(){

    alert(jQuery().length);

  })

})

</script>

</head>

<body>

  <button>点击查看效果</button>

</body>

</html>

语法结构二:

jQuery(selector,context)

参数列表:

参数 描述
selector 用来匹配元素的选择器。
context 可选。待查找的DOM元素集、文档或者jQuery对象。
如果没有指定,则就是当前整个文档。

如果没有指定,则就是当前整个文档。

实例代码:
实例一:



<!DOCTYPE HTML>

<html>

<head>

<meta charset="utf-8"/>

<meta name="author" content="http://www.phperz.com/" />

<title>jquery()函数-phperz</title>

<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>

<script type="text/javascript">

$(document).ready(function(){

  $("button").click(function(){

    $("li").css("color","red");

  })

})

</script>

</head>

<body>

<div>

  <ul>

    <li>DIV+CSS专区</li>

    <li>jQuery专区</li>

    <li>HTML专区</li>

  </ul>

</div>

<ul>

  <li>ASP专区</li>

  <li>phperz<span>欢迎您</span></li>

</ul>

<p>太阳出来了</p>

<button>点击查看效果</button>

</body>

</html>

以上代码能够将li元素中的字体颜色设置为红色。
实例二:



<!DOCTYPE HTML>

<html>

<head>

<meta charset="utf-8"/>

<meta name="author" content="http://www.phperz.com/" />

<title>jquery()函数-phperz</title>

<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>

<script type="text/javascript">

$(document).ready(function(){

  $("button").click(function(){

    $("li",$("div")).css("color","red");

  })

})

</script>

</head>

<body>

<div>

  <ul>

    <li>DIV+CSS专区</li>

    <li>jQuery专区</li>

    <li>HTML专区</li>

  </ul>

</div>

<ul>

  <li>ASP专区</li>

  <li>phperz<span>欢迎您</span></li>

</ul>

<p>太阳出来了</p>

<button>点击查看效果</button>

</body>

</html>

以上代码将div中li元素中的字体颜色设置为红色。
语法结构三:
将DOM元素、DOM元素数组转换成jQuery对象。

jQuery(element|elementArray)

参数列表:

参数 描述
element 要转换成jQuery对象的DOM元素。
elementArray 要转换成jQuery对象的DOM元素数组。

实例代码:
实例一:



<!DOCTYPE HTML>

<html>

<head>

<meta charset="utf-8"/>

<meta name="author" content="http://www.phperz.com/" />

<title>jquery()函数-phperz</title>

<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>

<script type="text/javascript">

$(document).ready(function(){

  $("button").click(function(){

    $(document.getElementById("first")).css("color","red");

  })

})

</script>

</head>

<body>

<div>

  <ul>

    <li id="first">DIV+CSS专区</li>

    <li>jQuery专区</li>

    <li>HTML专区</li>

  </ul>

</div>

<ul>

  <li>ASP专区</li>

  <li>phperz<span>欢迎您</span></li>

</ul>

<p>太阳出来了</p>

<button>点击查看效果</button>

</body>

</html>

以上代码可以将id为first的li元素中的字体颜色设置为红色。
实例二:



<!DOCTYPE HTML>

<html>

<head>

<meta charset="utf-8"/>

<meta name="author" content="http://www.phperz.com/" />

<title>jQuery()函数-phperz</title>

<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>

<script type="text/javascript">

$(document).ready(function(){

  $("button").click(function(){

    $(document.getElementsByTagName("li")).css("color","red");

  })

})

</script>

</head>

<body>

<div>

  <ul>

    <li id="first">DIV+CSS专区</li>

    <li>jQuery专区</li>

    <li>HTML专区</li>

  </ul>

</div>

<ul>

  <li>ASP专区</li>

  <li>phperz<span>欢迎您</span></li>

</ul>

<p>太阳出来了</p>

<button>点击查看效果</button>

</body>

</html>

语法结构四:

jQuery(callback)

jQuery(callback)是$(document).ready()的缩写形式,在上面的几个实例中都有使用。
它的作用是当文档加载完成以后再去执行callback函数
参数列表:
参数 描述
callback 文档加载完成之后要执行的函数。

实例代码:



<!DOCTYPE HTML>

<html>

<head>

<meta charset="utf-8"/>

<meta name="author" content="http://www.phperz.com/" />

<title>jQuery()函数-phperz</title>

<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>

<script type="text/javascript">

jQuery(function(){

  alert("文档加载完成了");

})

</script>

</head>

<body>

</body>

</html>

jQuery(function(){

    alert("文档加载完成了");

})

与下面代码功能是相同的:

$(document).ready(function(){

    alert("文档加载完成了");

})

希望本文所述对大家的jQuery程序设计有所帮助。

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务