从jQuery转换为javascript [英] Convert from jQuery to javascript

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

问题描述

我无法理解如何在不使用API​​ jQuery的情况下使代码处理本机javascript,我需要帮助人员。我刚开始学习编程。我将非常感激!

I can not understand how to get the code working on the "native" javascript without using the API jQuery, I need help guys. I just started to learn programming. I would be very grateful!

http://jsfiddle.net / P6YeA /

注意:当您点击屏幕的任何区域时 p 对象消失

Note: When you click in any area of ​​the screen p object disappears

推荐答案

这使用了jQuery函数.click(),. closest()和.fadeOut(),其中没有一个在一个简单的函数中重新实现是微不足道的。 click()需要为不同的浏览器事件引擎做一些工作。 fadeOut()在使用动画时会很繁琐。 .closest()会很复杂。你最好继续使用jQuery。

This uses the jQuery functions .click(), .closest() and .fadeOut(), none of which are trivial to re-implement in a simple function. click() requires a fair bit of working around for different browser event engines. fadeOut() would be fiddly as it uses animation. .closest() would just be complex. You'd be better of continuing to use jQuery.

如果你真的想要精益求精,你可以去掉你正在使用的jQuery部分。这不是非常简单简单...

If you really want to be lean, you could strip out the parts of jQuery you are using. This isn't extremely simple though...

无论哪种方式,你都可以通过相当复杂的Javascript代码来达到目的虽然,并且最后,你将拥有jQuery的一部分,但不完全,并且在你未来的项目中不能真正重复使用。

Either way, you will be up to your eyeballs in pretty complicated Javascript code for a fair while, and at the end of it, you'll have something that's part jQuery, but not quite, and not really re-usable in your future projects.

你可以考虑重写以使用比jQuery更精简的Javascript库,例如 Neon.js (注意:我写了Neon - 希望它是可以链接到它)。使用更纤薄的库至少可以确保您不必重新发明轮子。

You could consider re-writing to use a leaner Javascript library than jQuery, such as Neon.js (Note: I wrote Neon - hope it's OK to link to it). Using a slimmer library will at least ensure you don't have to re-invent the wheel.

但实际上,我认为最好的方法是继续使用jQuery - 它有一个开销,但它不是那么庞大,它会削弱你的网站。没那么糟糕。它已经实施。

But in actuality, I think the best course is to continue to use jQuery - it has an overhead, but it's not so massive that it's going to debilitate your site. It's not that bad. And it is implemented already.

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

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