jQuery插件与JavaScript [英] Jquery plugin Vs javascript

查看:112
本文介绍了jQuery插件与JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以在下面解释其优缺点.

Can somebody please explain the pros and cons for below.

我有一个获取url querystring参数的函数,但是我需要知道哪种是编写函数的最佳方法.例如:如果我使用jquery插件样式创建函数,那么每次我需要使用目标元素访问函数时,如下所示

Am having a function to get the url querystring parameters, but I need to know which is the best way to write the function. Eg: if i create the function using jquery plugin style, then every time I need to use a target element to access the function as below

$("#targetDom").getQueryString("name");

但是,如果我使用javascript类或javascript设计模式创建函数,则为

However, if I create the function using javascript classes or javascript design pattern, it would be

getQueryString("name");

这是一个小例子,但考虑到大型应用程序,哪种方法最好? jQuery插件方式有什么缺点吗?

This is a small example but considering large application which approach is best? is there any disadvantage in going with jquery plugin way?

此致

Navin

推荐答案

我不久前发现了这句话:

I found a while ago this sentence:

不学习jQuery.只需使用它即可.

Don't learn jQuery. Just use it.

我认为,这是对新手的最佳建议.

It's one of the best advices for a newbie, I think.

jQuery只是对javascript的补充.它简化了DOM遍历/操作,简化了事件处理等操作,但是您在了解原始Javascript之前就不应开始学习它.

jQuery is just an addition to javascript. It simplifies DOM traversing/manipulation, makes easy event handling and so on, but it is not something you should start learning before you know vanilla Javascript.

关于您的示例,这不是jQuery插件的最佳示例.

Regarding your example, it is not the best thought example for jQuery plugin.

您建议的语法($("#targetDom").getQueryString("name");)表示您将URL查询字符串视为以某种方式附加到HTML元素,这是错误的...

The syntax you suggested ($("#targetDom").getQueryString("name");) implies that you treat URL query string as attached somehow to the HTML element, which is wrong...

这篇关于jQuery插件与JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆