JQuery/Javascript 流程问题

发布于 2024-10-22 03:19:54 字数 654 浏览 4 评论 0原文

我继承了别人的项目并正在为其构建工作流程图。无需透露太多细节,离开的人是 Web 部门中唯一具有高级编程技能的人(那里的大多数人都从事生产工作和一些 HTML/CSS 工作)。我继承的项目是在 CodeIgniter 中开发的,并且严重依赖于 JQuery、AJAX 和 JSON。流程有点令人困惑,因此我概述了它。 (我正在回答这个问题,请耐心等待)

无论如何,这个部门的经理,让我们把他称为“工具”,不会允许他的员工学习任何这些东西。有一天他问我这是怎么回事,我说很好,除了我找不到一个变量被设置的位置,最初的开发人员正在使用 jquery 调用一些表单值来设置文件路径(他使用 #id. val()) 但我在代码中找不到#id。经理回复,呃,我还以为你是PHP大师呢。正如我所说,我们将称他为“工具”。

不管怎样,为了让他坚持下去,我决定与他的团队中的人分享这些流程页面,使它们非常具有描述性,并希望具有教育意义。我正在解释当从选择菜单进行更改时,jquery/javascript 如何识别该更改并在 JS 中触发相关代码。

然后我突然意识到我真的不知道 JS/JQ 是如何知道已经进行了更改的。我知道代码 ($("#id").change()...我有 AppleScript 背景,并且在该语言中有一个空闲命令,您基本上可以让一个脚本坐在后台观察并等待 X 发生(假设用户启动 Photoshop),当该事件发生时,其余代码会运行吗?

I've inherited someone else's project and am building a work flow diagram for it. Without getting into too many details the person who left was the only person in the web department with advanced programming skills (most people there do production work and some HTML/CSS stuff). The project I inherited was developed in CodeIgniter and leans heavily on JQuery, AJAX and JSON. The flow is a bit confusing hence my outlining it. (I'm getting to the question, bear with me)

Anyway, the manager of this department, let's refer to him as The Tool, won't allow his people to learn any of this stuff. He asked me the other day how it was coming and I said fine except I can't find where one variable is being set, the original developer is using jquery to call some form value to set a path to files (he using #id.val()) but I can't find #id anywhere in the code. The manager replies, eh, I thought you were the PHP guru. As I said, we shall refer to him as The Tool.

Anyway, to stick it to him somewhat I've decided to share these flow pages with people in his group, make them very descriptive and hopefully educational. I'm explaining how when a change is made from a select menu jquery/javascript recognizes that change and fires off related code in JS.

Then it dawned on me that I really didn't know how JS/JQ knew the change had been made. I know the code ($("#id").change()...I have an AppleScript background and in that language there's an idle command, you basically can have a script sit in the background observing and waiting for X to happen (say the user launches Photoshop) and when that event happens the rest of the code is run. Does JS do something similar?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抽个烟儿 2024-10-29 03:19:54

此代码:

$("#id").change()

告诉 jQuery(“$”)查找“id”值为(在本例中)“id”的元素,然后在该元素上触发“change”事件。这将导致注册的事件处理程序在要运行的元素上查找此类事件。这就是您在浏览器中使用 JavaScript 所做的几乎所有操作的基础:对事件的响应。

在某个地方,可能存在其中之一:

$("#id").change(function() { ... })

$("#id").live('change', function() { ... })

$("#id").bind('change', function() { ... })

但是,有多种方法可以识别元素以设置事件处理程序,因此可能很难找到。

This code:

$("#id").change()

tells jQuery (the "$") to find the element whose "id" value is (in this case) "id", and then to trigger a "change" event on the element. That will cause event handlers registered to look for such events on that element to be run. That's the basis of just about everything you do with JavaScript in a browser: responses to events.

Somewhere, there's probably one of these:

$("#id").change(function() { ... })

$("#id").live('change', function() { ... })

$("#id").bind('change', function() { ... })

There are many ways for the element to have been identified for setting up the event handlers, however, so it may be tricky to find.

还不是爱你 2024-10-29 03:19:54

在较新版本的 Chrome 中,您可以检查 html 元素,这还将显示与其绑定的“经典”事件。

越来越好的开发人员正在转向事件委托,例如:
http://developer.yahoo.com/yui/3/event/#delegate

这可能不会显示在 Chrome 中,但应该可以从代码中读取。

In newer versions of chrome you can inspect a html element, and this will also show 'classic' events that are bound to it.

Increasingly good developers are moving to event delegates such as:
http://developer.yahoo.com/yui/3/event/#delegate

Which will likely not show up in Chrome, but should be readable from the code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文