为什么人们使用jQuery进行基本操作? [英] Why do people use jQuery for basic operations?

查看:92
本文介绍了为什么人们使用jQuery进行基本操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名JS程序员,我一直在尝试使用jQuery,但遇到了一些令人费解的问题。

I am a JS programmer and I have been experimenting with jQuery a lot but have run into a couple puzzling aspects.

我觉得人们使用jQuery更多比必要的。我真的只是想知道为什么选择jQuery可能比仅使用纯JS更好。

I feel like people use jQuery for much more than necessary. I really just want to know why picking jQuery may be better than using just pure JS.

我知道webfx就像动画和淡化一样有意义但是对于像添加这样的东西事件监听器似乎同样易于使用

I know it makes sense for webfx like the animate and fades but for things like adding event listeners it seems just as easy to use

obj = document.getElementByID(_ID_);
obj.addEventListener("mousedown"...);

这就是我今天早些时候在StackOverflow上发现的关于为突出显示的文本执行操作的答案。 获取突出显示/选定的文字

An example of this is the answer I found on StackOverflow earlier today about performing an action for highlighted text. Get the Highlighted/Selected text

http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html

该人使用绑定功能来处理文档。为什么使用bind而不是addEventListener。同样使用jQuery,一切都需要包含在.ready()方法中,这比(或者为什么选择它更好)

The guy uses the bind function to the document. Why use bind rather than addEventListener. Also with jQuery everything needs to be included in the .ready() method how is this better than (or why choose it over)

document.addEventListener('load', function () { ... }, false);

还有其他一些我见过的jQuery使我感到困惑,我希望你们能发光一些对我而言。

There are other times I have seen jQuery used that puzzled me, I hope you guys can shine some light on it for me.

推荐答案

人们使用jQuery因为它更简单,更容易,更强大,并且因为它可以帮助他们忘记IE。

People use jQuery because it's simpler, easier, and more powerful, and because it helps them forget about IE.

回答您的具体问题:


  1. 否则,你需要为IE调用 attachEvent

    此外,jQuery事件处理具有更简单的语法,并支持实时事件。

  1. Otherwise, you need to call attachEvent for IE.
    Also, jQuery event handling has simpler syntax, and supports live events.

jQuery不要求你把所有东西放在 ready 处理程序中;将代码移动到页面底部并立即执行它实际上更好。

document.addEventListener('load',...),jQuery的 ready 事件不会等待加载图像。

此外,它在IE中运行,即使它仍然运行你的代码文档已经加载。

jQuery does not require you to put everything in a ready handler; it's actually better to move your code to the bottom of the page and execute it immediately.
Unlike document.addEventListener('load', ...), jQuery's ready event will not wait for images to load.
Also, it works in IE, and it will still run your code even if the document already loaded.

这篇关于为什么人们使用jQuery进行基本操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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