JavaScript的效果在阿贾克斯的答复无法正常工作无法正常、效果、工作、JavaScript

2023-09-10 19:36:29 作者:7冄7號°

我是新的AJAX。我寻觅了很多在互联网上,但只得到了基本的AJAX步骤。现在我正在写codeS使用AJAX,但一个共同的问题,我面对不断。

当我把返回的HTML页面的特定ID文本,JavaScript特效不工作。 CSS的工作方式类似表格排序,jQuery效果或其他效果不工作正常,但JavaScript特效。我知道我在这里缺少一些概念。但没有得到任何有效的解决。

请建议我该怎么办?而这背后的概念...

解决方案 因不敢坐飞机而错过比赛的职业球员也就只有他了吧

您要添加到DOM(页)新的HTML是不存在的,当你的jQuery跑在第一时间和绑定事件到页面上的元素。你可能会使用$(东西)。点击(...)或.bind(点击,...)。相反,这些使用委托函数从jQuery的。代表一般比较灵活,比现场快。比如你不能stopPropagation在一个'活'的结合。

jQuery的代表

为什么委派比活

下面是另一个 SO回答解释委托的好处

I am new in AJAX. I have searched a lot on Internet but only got basic AJAX steps. Now I am writing codes using AJAX but a common problem I am facing continuously.

When I place return text in the particular id of HTML page, Javascript effects do not work. CSS works fine but Javascript effects like table sorting, jQuery effects or any other effect does not work. I know I am missing some concept here. But didn't get any effective answer.

Please suggest me what should I do? And what is the concept behind this...

解决方案

The new HTML you're adding to the DOM (page) didn't exist when your jquery ran the first time and bound events to elements on the page. You're probably using $("something").click(...) or .bind("click", ...). Instead of these use the delegate function from jquery. Delegate is generally more flexible and faster than live. For instance you can not stopPropagation in a 'live' binding.

Jquery Delegate

Why Delegate is better than Live

Here is another SO answer that explains the benefits of delegate