12
A
回答
10
// Allows chainable logging
// USAGE: $('#someDiv').hide().log('div hidden').addClass('someClass');
// Demo : http://jsbin.com/odeke
jQuery.log = jQuery.fn.log = function (msg) {
if (window.console && window.console.log) {
console.log("%s: %o", msg, this);
}
return this;
};
1
的validation插件是真棒短的片段。在ASP.NET MVC应用程序中使用它来动态验证客户端上的东西使用Ajax ...甚至基于用户输入返回的自定义错误消息...非常酷。
0
http://plugins.jquery.com/承载各种各样的插件,无论大小,都将是一个比这个线程更加全面和有用的资源,对不起。
-2
只是获取/设置元素ID的快捷方式。
(function($) {
$.fn.id = function(newDOMID){
var $this = $(this);
if($this.attr('id')){
if(!newDOMID){
$this.id.getID($this);
}
else {
$this.id.setID($this,newDOMID);
}
}
else {
alert('The target no longer appears to be a part of the DOM!')
}
};
$.fn.id.getID = function($this){
return $this.attr('id');
};
$.fn.id.setID = function($this,newDOMID){
$this.attr('id',newDOMID);
return this
};
})(jQuery);
它是jQuery插件网站上的jID。
4
您可以使用它来查看选择器是否存在。
if($.exists('#mydiv')) { }
$.exists = function(selector) {
return ($(selector).length);
}
0
啊 我有点掉最初的问题,但如果有“获取/设置一个ID”片断,然后 我有一些代码来创建唯一的ID:
$.increment = function(){
var me = arguments.callee;
if (!me.count) me.count = 0;
return ++me.count;
}
$.domToSelector = function (jq, options){
var selectors = [], i = 0; defaults = {}, opts = $.extend(defaults,options);
$(jq).each(function(){
var $node = $(this);
if ($node.attr('id')){
selectors[i] = '#'+$(this).attr('id');
}
else{
var customId = ''+new Date;
customId = customId.replace(/ /g, '').replace(/:/g, '').replace(/\+/g, '');
customId = customId+'_'+$.increment();
if (opts.prefix) customId = opts.prefix+customId;
$node.attr('id', customId);
selectors[i] = '#'+customId;
}
i++;
});
if (selectors.length == 1) selectors = selectors[0];
return selectors;
}
1
快速,方便AJAX:
下让你做出像锚
<a href='http://www.google.com/' rel='#myselector' class='ajax' />
它对href
URL执行AJAX查询,并将结果注入由选择器在定位点rel
属性中定义的第一个元素。
// Allow hrefs with the class 'ajax' and a rel attribute set with a selector to load content via ajax into the selected element.
$('.ajax').unbind('click').click
(
function(e)
{
$($(this).attr('rel')).load($(this).attr("href"));
e.preventDefault();
}
);
4
解释的页面,外部链接的绝对URL,并将它们设置在打开一个新标签,并具有友好的标题&类特殊造型。
$("#content [href^='http']:not(a:has('img'))").each(function(){$(this).attr("target", "_blank").addClass("external").attr("title", "External Link to " + $(this).attr("href"))});
0
扩展选择器,即编写自己的自定义选择器。下面是两个样本:
$(document).ready(function(){
$.extend($.expr[':'], {
inputEmpty: inputEmpty,
inputNotEmpty: inputNotEmpty
});
});
function inputEmpty(el) {
return $(el).val() == "";
}
function inputNotEmpty(el) {
return $(el).val() != "";
}
相关问题
- 1. 你如何教好编程好的东西?
- 2. 你如何签署你的Firefox扩展?
- 3. JavaScriptCore不能工作的其他任何东西'你好,世界'
- 4. PHP类扩展 - 运行父函数之前运行的东西
- 5. 你认为在页面上使用很多CSS3的东西是不好的吗?
- 6. 除了“你好”的东西,还有什么好的Phonegap教程吗?
- 7. 你为什么要把/ *放在你的jQuery函数中?
- 8. jQuery定制核心:只使用你需要的东西
- 9. 字符串到DateTime?扩展转换。*或更好的东西
- 10. kohana 3 - 不显示任何东西你好世界控制器
- 11. 你如何测试小东西? (Eclipse Android)
- 12. 你能扩展self.included吗?
- 13. 扩展扩展方法?或者其他的东西?
- 14. 你会如何给Android的东西命名为蓝牙服务?
- 15. 你在哪里扩展你的rails应用程序中的类?
- 16. 扩展jQuery的$ .post()函数
- 17. 扩展jQuery的ajax函数
- 18. 你如何以编程方式打开你的扩展?
- 19. 你用什么来测试你的浏览器扩展/ BHO?
- 20. HTML标记的非标准属性。好东西?坏事?你的想法?
- 21. 我可以从iPhone获得什么东西,当你开发
- 22. 你如何打包Heroku的扩展?
- 23. 你如何检查devtools.html的扩展名?
- 24. jQuery的:东西
- 25. Scala添加方法扩展东西
- 26. Visual Studio继续扩展东西
- 27. 文件和组织您的实验,你觉得每一个好东西,你了解它
- 28. 你可以添加你称之为静态方法的扩展方法吗?
- 29. 你如何存储你学到的所有东西以及你想要保存的信息?
- 30. 当你知道你调用的方法会抛出同样的东西时,你会抛出异常吗?
该网站的结构是这样的,使用适当的标签和标题,可以找到特定的问题和答案,为特定的搜索。如果我需要一个日志插件,我不会搜索“[jquery]扩展程序好东西”,我会搜索“[jquery-plugin] logging”或搜索jQuery插件存储库。 – Shog9 2009-01-11 17:38:16
有趣的是如何得到3000视图然后http://stackoverflow.com/questions/271398/post-your-extension-goodies-for-c-net-codeplex-com-extensionoverflow。 – redsquare 2009-01-11 17:42:03
Shog - 这个项目变成了一个完整的项目,所以我想你必须从你认为的那个崇高的鲈鱼跳下来。 – redsquare 2009-01-11 17:48:17