随机JQUERY片段
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了随机JQUERY片段相关的知识,希望对你有一定的参考价值。
Useful random jQuery snippets.
//Remove a word with jQuery var el = $('#id'); //jQuery timer callback functions window.setTimeout(function() { $('#id').empty(); }, 1000); //Verify that an element exists in jQuery if ($('#id').length) { // do stuff } //Dynamically adding <div> elements with jQuery $('<div>hello</div>').appendTo(document.body); //Searching for Text with jQuery //This function performs a recursive search for nodes that contain a pattern. Arguments are //a jQuery object and a pattern. The pattern can be a string or a regular expression. $.fn.egrep = function(pat) { var out = []; var textNodes = function(n) { if (n.nodeType == Node.TEXT_NODE) { var t = typeof pat == 'string' ? n.nodeValue.indexOf(pat) != -1 : pat.test(n.nodeValue); if (t) { out.push(n.parentNode); } } else { $.each(n.childNodes, function(a, b) { textNodes(b); }); } }; this.each(function() { textNodes(this); }); return out; }; //Case-Insensitive Contains Check //By using case-insensitive regular expressions, this becomes rather easy: var pattern = /exp/i; $('#id').filter(function() { return pattern.test($(this).text()); }); //Reload an IFrame //Accessing the contentWindow property to obtain the location object. $('#iframe').each(function() { this.contentWindow.location.reload(true); }); //Callback for IFrame Loading //With the onload event, your code is called when an IFrame has finished loading. $('#iframe').load(function() { // do something });
以上是关于随机JQUERY片段的主要内容,如果未能解决你的问题,请参考以下文章
Visual Studio 2012-2019的130多个jQuery代码片段。
markdown 在WordPress中使用jQuery代码片段