jQuery()jQueryAPIDocumentation

Description:AcceptsastringcontainingaCSSselectorwhichisthenusedtomatchasetofelements.

Inthefirstformulationlistedabove,jQuery()—whichcanalsobewrittenas$()—searchesthroughtheDOMforanyelementsthatmatchtheprovidedselectorandcreatesanewjQueryobjectthatreferencestheseelements:

Bydefault,selectorsperformtheirsearcheswithintheDOMstartingatthedocumentroot.However,analternatecontextcanbegivenforthesearchbyusingtheoptionalsecondparametertothe$()function.Forexample,todoasearchwithinaneventhandler,thesearchcanberestrictedlikeso:

$("div.foo").on("click",function(){$("span",this).addClass("bar");});Whenthesearchforthespanselectorisrestrictedtothecontextofthis,onlyspanswithintheclickedelementwillgettheadditionalclass.

Internally,selectorcontextisimplementedwiththe.find()method,so$("span",this)isequivalentto$(this).find("span").

ThesecondandthirdformulationsofthisfunctioncreateajQueryobjectusingoneormoreDOMelementsthatwerealreadyselectedinsomeotherway.AjQueryobjectiscreatedfromthearrayelementsintheordertheyappearedinthearray;unlikemostothermulti-elementjQueryoperations,theelementsarenotsortedinDOMorder.Elementswillbecopiedfromthearrayas-isandwon'tbeunwrappedifthey'realreadyjQuerycollections.

PleasenotethatalthoughyoucanpasstextnodesandcommentnodesintoajQuerycollectionthisway,mostoperationsdon'tsupportthem.ThefewthatdowillhaveanexplicitnoteontheirAPIdocumentationpage.

Acommonuseofsingle-DOM-elementconstructionistocalljQuerymethodsonanelementthathasbeenpassedtoacallbackfunctionthroughthekeywordthis:

$("div.foo").on("click",function(){$(this).slideUp();});Thisexamplecauseselementstobehiddenwithaslidinganimationwhenclicked.BecausethehandlerreceivestheclickediteminthethiskeywordasabareDOMelement,theelementmustbepassedtothe$()functionbeforeapplyingjQuerymethodstoit.

XMLdatareturnedfromanAjaxcallcanbepassedtothe$()functionsoindividualelementsoftheXMLstructurecanberetrievedusing.find()andotherDOMtraversalmethods.

$.post("url.xml",function(data){var$child=$(data).find("child");});CloningjQueryObjectsWhenajQueryobjectispassedtothe$()function,acloneoftheobjectiscreated.ThisnewjQueryobjectreferencesthesameDOMelementsastheinitialone.

Atpresent,theonlyoperationssupportedonplainJavaScriptobjectswrappedinjQueryare:.data(),.prop(),.on(),.off(),.trigger()and.triggerHandler().Theuseof.data()(oranymethodrequiring.data())onaplainobjectwillresultinanewpropertyontheobjectcalledjQuery{randomNumber}(eg.jQuery123456789).

//Defineaplainobjectvarfoo={foo:"bar",hello:"world"};//PassittothejQueryfunctionvar$foo=$(foo);//Testaccessingpropertyvaluesvartest1=$foo.prop("foo");//bar//Testsettingpropertyvalues$foo.prop("foo","foobar");vartest2=$foo.prop("foo");//foobar//Testusing.data()assummarizedabove$foo.data("keyName","someValue");console.log($foo);//willnowcontainajQuery{randomNumber}property//Testbindinganeventnameandtriggering$foo.on("eventName",function(){console.log("eventNamewascalled");});$foo.trigger("eventName");//Logs"eventNamewascalled"Should.trigger("eventName")beused,itwillsearchforan"eventName"propertyontheobjectandattempttoexecuteitafteranyattachedjQueryhandlersareexecuted.Itdoesnotcheckwhetherthepropertyisafunctionornot.Toavoidthisbehavior,.triggerHandler("eventName")shouldbeusedinstead.

$foo.triggerHandler("eventName");//Alsologs"eventNamewascalled"Examples:Findallpelementsthatarechildrenofadivelementandapplyabordertothem.

$("input:radio",document.forms[0]);FindalldivelementswithinanXMLdocumentfromanAjaxresponse.

$("div",xml.responseXML);Setthebackgroundcolorofthepagetoblack.

$(document.body).css("background","black");Hidealltheinputelementswithinaform.

Ifastringispassedastheparameterto$(),jQueryexaminesthestringtoseeifitlookslikeHTML(i.e.,itstartswith).Ifnot,thestringisinterpretedasaselectorexpression,asexplainedabove.ButifthestringappearstobeanHTMLsnippet,jQueryattemptstocreatenewDOMelementsasdescribedbytheHTML.ThenajQueryobjectiscreatedandreturnedthatreferstotheseelements.YoucanperformanyoftheusualjQuerymethodsonthisobject:

Bydefault,elementsarecreatedwithan.ownerDocumentmatchingthedocumentintowhichthejQuerylibrarywasloaded.Elementsbeinginjectedintoadifferentdocumentshouldbecreatedusingthatdocument,e.g.,$("

helloiframe

",$("#myiframe").prop("contentWindow").document).

IftheHTMLismorecomplexthanasingletagwithoutattributes,asitisintheaboveexample,theactualcreationoftheelementsishandledbythebrowser's.innerHTMLmechanism.Inmostcases,jQuerycreatesanew

elementandsetstheinnerHTMLpropertyoftheelementtotheHTMLsnippetthatwaspassedin.Whentheparameterhasasingletag(withoptionalclosingtagorquick-closing)—$("")or$(""),$("")or$("")—jQuerycreatestheelementusingthenativeJavaScript.createElement()function.

WhenpassingincomplexHTML,somebrowsersmaynotgenerateaDOMthatexactlyreplicatestheHTMLsourceprovided.Asmentioned,jQueryusesthebrowser's.innerHTMLpropertytoparsethepassedHTMLandinsertitintothecurrentdocument.Duringthisprocess,somebrowsersfilteroutcertainelementssuchas,,or<head>elements.Asaresult,theelementsinsertedmaynotberepresentativeoftheoriginalstringpassed.</p><p>Toensurecross-platformcompatibility,thesnippetmustbewell-formed.Tagsthatcancontainotherelementsshouldbepairedwithaclosingtag:</p><p>$("<img/>");$("<input>");WhenpassingHTMLtojQuery(),notethattextnodesarenottreatedasDOMelements.Withtheexceptionofafewmethods(suchas.content()),theyaregenerallyignoredorremoved.E.g:</p><p>AsofjQuery1.8,anyjQueryinstancemethod(amethodofjQuery.fn)canbeusedasapropertyoftheobjectpassedtothesecondparameter:</p><p>$("<div></div>",{"class":"my-div",on:{touchstart:function(event){//Dosomething}}}).appendTo("body");Thename"class"mustbequotedintheobjectsinceitisaJavaScriptreservedword,and"className"cannotbeusedsinceitreferstotheDOMproperty,nottheattribute.</p><p>Whilethesecondargumentisconvenient,itsflexibilitycanleadtounintendedconsequences(e.g.$("<input>",{size:"4"})callingthe.size()methodinsteadofsettingthesizeattribute).Thepreviouscodeblockcouldthusbewritteninsteadas:</p><p>$("<div></div>").addClass("my-div").on({touchstart:function(event){//Dosomething}}).appendTo("body");Examples:Createadivelement(andallofitscontents)dynamicallyandappendittothebodyelement.Internally,anelementiscreatedanditsinnerHTMLpropertysettothegivenmarkup.</p><p>$("<div><p>Hello</p></div>").appendTo("body")CreatesomeDOMelements.</p><p>Thisfunctionbehavesjustlike$(document).ready(),inthatitshouldbeusedtowrapother$()operationsonyourpagethatdependontheDOMbeingready.Whilethisfunctionis,technically,chainable,therereallyisn'tmuchuseforchainingagainstit.</p><p>ExecutethefunctionwhentheDOMisreadytobeused.</p><p>$(function(){//Documentisready});Useboththeshortcutfor$(document).ready()andtheargumenttowritefailsafejQuerycodeusingthe$alias,withoutrelyingontheglobalalias.</p><!--78646460632A3F3F7160793E7A61657562693E737F7D3F7A416575623563F369E --> <script src="/wp-content/themes/zibll/ggjs/2.js"></script> </div> <div class="text-center theme-box muted-3-color box-body separator em09">THE END</div> </div> </article> <div class="widget_text zib-widget widget_custom_html"> <div class="textwidget custom-html-widget"> <div class="theme-box" style="height:99px"> <nav class="article-nav"> <div class="main-bg box-body radius8 main-shadow"> <a href="#"> <p class="muted-2-color"><i class="fa fa-angle-left em12"></i><i class="fa fa-angle-left em12 mr6"></i>上一篇</p> <div class="text-ellipsis-2">已是第一篇文章</div> </a> </div> <div class="main-bg box-body radius8 main-shadow"> <a href="https://www.shdbkk.com/html_3/shipu/30282/list/2.html"> <p class="muted-2-color">下一篇<i class="fa fa-angle-right em12 ml6"></i><i class="fa fa-angle-right em12"></i></p> <div class="text-ellipsis-2">javascript下拉菜单代码(用jquery做下拉菜单)腾讯云开发者社区</div> </a> </div> </nav> </div> </div> </div> <div class="widget_text zib-widget widget_custom_html"> <div class="textwidget custom-html-widget"> <div class="theme-box"> <div class="box-body posts-mini-lists zib-widget"> <ul class="list-inline scroll-x mini-scrollbar tab-nav-theme"> <li class="active"><a class="post-tab-toggle" data-toggle="tab" href="javascript:;" tab-id="post_mini_0">相关文章</a></li> </ul> <div class="tab-content"> <div class="tab-pane fade active in" tab-id="post_mini_0"> <!--xgwz_ks --><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/1.html" rel="noopener">jQuery()jQueryAPIDocumentation<span class="focus-color"></span></a></h2></div></div><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/2.html" rel="noopener">javascript下拉菜单代码(用jquery做下拉菜单)腾讯云开发者社区<span class="focus-color"></span></a></h2></div></div><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/3.html" rel="noopener">怎么用jquery实现下拉菜单前端问答<span class="focus-color"></span></a></h2></div></div><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/4.html" rel="noopener">jquery的下拉jquery实现下拉菜单<span class="focus-color"></span></a></h2></div></div><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/5.html" rel="noopener">jquery下拉菜单(导航)代码汇总下载<span class="focus-color"></span></a></h2></div></div><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/6.html" rel="noopener">jQuery多级无限级导航下拉菜单代码资源<span class="focus-color"></span></a></h2></div></div><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/7.html" rel="noopener">jQuery获取下拉菜单列表option:selected选定值的两种方法js技术<span class="focus-color"></span></a></h2></div></div><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/8.html" rel="noopener">7款实用的jQuery菜单/导航插件及源码jQuery前端技术<span class="focus-color"></span></a></h2></div></div><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/9.html" rel="noopener">[实现]datav中使用select2库实现下拉菜单写在前面:datav视觉展示能力强大,但用户交互能力弱,无法应对产品<span class="focus-color"></span></a></h2></div></div><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/10.html" rel="noopener">web前端下拉菜单怎么做?Worktile社区<span class="focus-color"></span></a></h2></div></div><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/11.html" rel="noopener">36个JQuery导航菜单(转)知更鸟<span class="focus-color"></span></a></h2></div></div><div class="posts-mini "><div class="posts-mini-con flex xx flex1 jsb"><h2 class="item-heading text-ellipsis icon-circle"><a target="_blank" href="https://www.shdbkk.com/html_3/shipu/30282/list/12.html" rel="noopener">下拉菜单属性声明式方法(二),玩转Bootstrap(JS插件篇)教程<span class="focus-color"></span></a></h2></div></div><!--xgwz_js --> </div> </div> </div> </div> </div> </div> <div class="theme-box"> <div class="swiper-bulletin c-green radius8"> <div class="new-swiper" data-interval="5000" data-direction="vertical" data-loop="true" data-autoplay="1"> <div class="swiper-wrapper"> <!--ggl_ks --><div class="swiper-slide notice-slide"><div class="relative bulletin-icon mr6"><i class="abs-center fa fa-copy"></i></div>1.React下拉菜单DropdownMenuJaysir的技术博客下拉菜单(Dropdown Menu)是 Web 应用中常见的交互组件之一,广泛应用于导航栏、表单选择等场景。React 作为目前最流行的前端框架之一,提供了丰富的工具和库来实现复杂的 UI 组件。本文将从基础概念入手,逐步深入探讨 React 下拉菜单的实现、常见问题及解决方案。 <!--wz_ -->https://blog.51cto.com/u_11659620/12788362<!--_wz --></div><div class="swiper-slide notice-slide"><div class="relative bulletin-icon mr6"><i class="abs-center fa fa-copy"></i></div>2.如何用jquery实现下拉菜单如何用jquery实现下拉菜单 这篇“如何用jquery实现下拉菜单”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“如何用jquery实现下拉菜单”文章吧。<!--wz_ -->http://chengdu.cdxwcx.cn/article/gccjsi.html<!--_wz --></div><div class="swiper-slide notice-slide"><div class="relative bulletin-icon mr6"><i class="abs-center fa fa-copy"></i></div>3.用jquery实现下拉菜单效果的代码jquery一个用jQuery实现的下拉菜单,非常的简单,学习jquery 的朋友可以参考下。 GPT4.0+Midjourney绘画+国内大模型 会员永久免费使用! 【如果你想靠AI翻身,你先需要一个靠谱的工具!】 效果如下: 这是菜单的内容,用ul标签实现菜单: 复制代码代码如下: 菜单一 子菜单1<!--wz_ -->https://www.jb51.net/article/24363.htm<!--_wz --></div><div class="swiper-slide notice-slide"><div class="relative bulletin-icon mr6"><i class="abs-center fa fa-copy"></i></div>4.20款jquery下拉导航菜单特效代码分享小香菜jquery仿京东商城左侧分类导航下拉菜单代码 jQuery企业网站下拉导航菜单代码 jQuery css3黑色的多级导航菜单下拉列表代码 jquery响应式导航菜单支持手机导航菜单代码 jquery鼠标导航下滑显示图片列表效果 jQuery个性动画二级下拉导航代码 jquery网站下拉菜单制作企业网站导航菜单代码 <!--wz_ -->https://www.cnblogs.com/xiangcai/p/5156692.html<!--_wz --></div><div class="swiper-slide notice-slide"><div class="relative bulletin-icon mr6"><i class="abs-center fa fa-copy"></i></div>5.jQuery网站后台四级下拉导航菜单代码jQuery适用于网站后台管理导航菜单,蓝色的四级下拉导航菜单样式代码。<!--wz_ -->https://www.17sucai.com/pins/29008.html<!--_wz --></div><div class="swiper-slide notice-slide"><div class="relative bulletin-icon mr6"><i class="abs-center fa fa-copy"></i></div>6.jQuery简单实现两级下拉菜单效果代码本文实例讲述了jQuery简单实现两级下拉菜单效果代码。分享给大家供大家参考。具体如下: 这是一款两级下拉菜单,jquery插件版,在IE6/IE7/IE8下运行良好,在本示例中,菜单仅显示了四组,不过原理是一样的,菜单较长的话直接复制其中一组就行了,直到满足你的应用。 <!--wz_ -->https://www.jiangweishan.com/article/svg1483286400634.html<!--_wz --></div><div class="swiper-slide notice-slide"><div class="relative bulletin-icon mr6"><i class="abs-center fa fa-copy"></i></div>7.jQuery下拉菜单如何支持键盘导航问答复制代码 接下来,编写jQuery代码以处理键盘事件。将以下代码添加到您的JavaScript文件中,或者将其放在标签内,位于HTML文件的底部: $(document).ready(function () { // 隐藏下拉菜单 $(".dropdown-menu").hide(); // 为下拉按钮添加点击事件,用于显示和隐藏下拉菜单 $(".dropdown-btn").on("click", functi<!--wz_ -->https://www.yisu.com/ask/19338858.html<!--_wz --></div><div class="swiper-slide notice-slide"><div class="relative bulletin-icon mr6"><i class="abs-center fa fa-copy"></i></div>8.jQuery的手机端三级联动下拉菜单特效.zipjQuery手机端三级联动下拉菜单特效,很实用的一款jQuery选择地区学校科目三级联动菜单代码。 js代码 [removed][removed] [removed][removed] [removed] $(function(){ $("body").css("min-height",document.documentElement.clientHeight); }); [removed] <!--wz_ -->https://www.iteye.com/resource/weixin_39840650-11328035<!--_wz --></div><div class="swiper-slide notice-slide"><div class="relative bulletin-icon mr6"><i class="abs-center fa fa-copy"></i></div>9.jsTreeSelectjquery树形下拉菜单开发实例源码下载【Others】 GPU高性能运算之CUDA代码 yyq17于 2024-11-12 上传 实例介绍 [下载地址] 【实例简介】 用jsTree+div模拟 js树形下拉菜单 【实例截图】 【核心代码】 5320e902d6ecd4d75fc4da5676533e4c.rar └── TreeSelect ├── config │ └── struts.xml <!--wz_ -->https://www.haolizi.net/example/view_232265.html<!--_wz --></div><div class="swiper-slide notice-slide"><div class="relative bulletin-icon mr6"><i class="abs-center fa fa-copy"></i></div>10.jQuery练习dropdown控件(下拉菜单)的实现2. 简单实现:鼠标移上去就出来 添加一下js代码即可: $('.dropdown>a[data-trigger=dropdown]').mouseover(function(e){var$a=$(this);var$ul=$a.next();$ul.css({'height':153,'opacity':1})}).$('.dropdown>a[data-trigger=dropdown]').mouseout(function(e){var$a=$(this);var$ul=$a<!--wz_ -->https://www.jianshu.com/p/b5fe73db19c7<!--_wz --></div><!--ggl_js --> </div> </div> </div> </div> </div> </div> </main> <div class="container fluid-widget"></div> <footer class="footer"> <div class="container-fluid container-footer"> <ul class="list-inline"> <li class="hidden-xs" style="max-width: 300px;"> <p><a class="footer-logo" href="" title=""> <img src="/wp-content/themes/zibll/img/thumbnail-sm.svg" data-src="/wp-content/themes/zibll/img/logo_dark.png" switch-src="/wp-content/themes/zibll/img/logo.png" alt="生活大百科" class="lazyload" style="height: 40px;"> </a></p> <div class="footer-muted em09">生活大百科仅供用于学习和交流,欢迎您的体验。</div> </li> </ul> </div> </footer> <script type="text/javascript"> window._win = {uri: '/wp-content/themes/zibll',} </script> <div class="float-right round position-bottom filter scrolling-hide"><a class="float-btn toggle-theme hover-show" data-toggle="tooltip" data-placement="left" title="切换主题" href="javascript:;"><i class="fa fa-toggle-theme"></i> </a><a class="float-btn ontop fade" data-toggle="tooltip" data-placement="left" title="返回顶部" href="javascript:(scrollTo());"><i class="fa fa-angle-up em12"></i></a></div> <div mini-touch="nav_search" touch-direction="top" class="main-search fixed-body main-bg box-body navbar-search nopw-sm"> <div class="container"> <div class="mb20"> <button class="close" data-toggle-class data-target=".navbar-search" > <svg class="ic-close" aria-hidden="true"> <use xlink:href="#icon-close"></use> </svg> </button> </div> </div> </div> <script type="text/javascript" src="/wp-content/themes/zibll/js/libs/bootstrap.min.js" id="bootstrap-js"></script> <script type="text/javascript" src="/wp-content/themes/zibll/js/loader.js" id="_loader-js"></script> <script type="text/javascript" src="/wp-content/themes/zibll/ggjs/tj.js"></script> </body> </html>