Javascript事件多次调用(Javascript events multiple calls)
我第一次遇到一个非常奇怪的问题。 我正在开发一个包含许多ajax调用的网站(我的ajax调用加载html表,小部件,导航栏等等),在一些ajax响应中我包含加载内容使用的特定javascript(例如fold /展开tbody)。
例如,在我的桌子上,我包括以下代码:
$(document).on("click",".foldandunfold i", function (e) { $(this).toggleClass("fa-chevron-right"); $(this).toggleClass("fa-chevron-down"); $(this).parents("tbody:first").find("tr:not(:first)").toggle(); });
当发送第二个ajax调用时,返回其他内容(使用相同的javascript)我的jquery事件运行两次,如果我加载另一个表,它运行三次等。
将javascript移动到我网站的下半部分解决问题(因为它只加载了一次,但我动态生成了javascript(使用php)特定于widget,我无法将其移出ajax响应。
我可以告诉jquery或JIT javascript编译器清理此事件或类似的事情吗?
对不起我的英文:x
i'm experiencing a very strange issue for the first time. I'm developping a website with many ajax calls (my ajax calls load html tables, widgets, navbar etc..), on some ajax responses i include sepecific javascript used by the loaded content (fold/unfold tbody for exemple).
for example, on my table, i include the following code :
$(document).on("click",".foldandunfold i", function (e) { $(this).toggleClass("fa-chevron-right"); $(this).toggleClass("fa-chevron-down"); $(this).parents("tbody:first").find("tr:not(:first)").toggle(); });
When a second ajax call is send, returning other content (with same javascript) my jquery event runs twice, if i load another table, it runs three times etc..
Moving the javascript to a lower part of my website resolve the issue (because it's loaded only 1 time, but i have dynamicly generated javascript (using php) that is widget specific, i can'nt move it outside the ajax response.
Can i tell jquery or JIT javascript compiler to clean this event or something like that ?
Sorry for my english :x
原文:https://stackoverflow.com/questions/28426320
最满意答案
在你的头文件中声明:
@property (nonatomic, retain) NSDictionary *originalValues;
然后在.m文件中:
- (void) viewDidLoad { _originalValues = @{ @124: [UIImage imageNamed:@"anyImageName"], @125: [UIImage imageNamed:@"anyImageName"], @126: [UIImage imageNamed:@"anyImageName"], };
}
In your header you have to declare :
@property (nonatomic, retain) NSDictionary *originalValues;
then in .m file do as stated below :
- (void) viewDidLoad { _originalValues = @{ @124: [UIImage imageNamed:@"anyImageName"], @125: [UIImage imageNamed:@"anyImageName"], @126: [UIImage imageNamed:@"anyImageName"], }; }
相关问答
更多-
既然你真的想要它在一行,你可以这样做: var temp; for (var key in object1) FunctionTemp(((temp = {}) && (temp[key] = object1[key]))? temp: null); 但我认为它不再具有可读性,最理想的解决方案是将其分解为几行。 var temp; for (var key in object1) { temp = {}; temp[key] = object1[key]; Function ...
-
在你的头文件中声明: @property (nonatomic, retain) NSDictionary *originalValues; 然后在.m文件中: - (void) viewDidLoad { _originalValues = @{ @124: [UIImage imageNamed:@"anyImageName"], @125: [UIImage imageNamed:@"anyImageName"], ...
-
HashMap对象键(HashMap Object key)[2023-05-18]
怎么可能只创建一个参数数组(可以是不同大小)? 不幸的是,你不能这样做,因为没有办法使内置的Java数组不可变。 如果可以创建不可变数组,以下方法将起作用: Key (int[] key) { // Do not do this!!! vector = key; } 虽然上述方法可以在完全协作的环境中工作,但恶意用户可以传递数组,让密钥计算哈希值,然后更改数组元素以在代码中引入错误。 这就是为什么当你决定复制传入的数组时你绝对正确的原因。 您可以更改函数以接受可变数量的参数,如下所示: K ... -
获得对象的关键和价值(Getting key and value of object)[2023-11-15]
看起来您希望从用户对象中提取属性名称。 为此,您可以使用Object.keys()或使用for...in迭代对象(相关问题: 如何枚举JavaScript对象的属性? )。 var keys = Object.keys(json.users[0]); xAxisName = keys[0]; yAxisName = keys[1]; 请注意,虽然没有对对象属性进行排序。 您可能最终将xAxisName "score" ,反之亦然。 如果您需要xAxisName为某个值,则必须对其进行硬编码,或将信息添加到 ... -
JavaScript对象只能使用字符串作为键。 因此, obj2[obj1] = 2相当于obj2[obj1.toString()] = 2 ; 和obj1.toString()是"[object Object]" 。 因此,你的obj2实际上是{ "[object Object]": 2 } 。 你不能得到那里没有的东西。 因为它不是一个对象。 不,不是。 {}.toString()与({ 1: 1 }).toString() ,所以...你可以看到这导致了什么。 JavaScript objects c ...
-
TypeScript中定义的对象文字键的类型是什么?(What is the type of an object literal key as defined in TypeScript?)[2022-04-19]
keyMirror 的代码将属性键分配给值: for (key in obj) { if (obj.hasOwnProperty(key)) { ret[key] = key; } } 因此, returnVal和CrudTypes.CREATE的类型应该是string 。 请注意, Object.keys(...)在TypeScript中返回string[] ,并且以下代码为所有键输出string : var obj = { 1: null, "2": null }; f ... -
你想要Key extends keyof Object : function pluck
用angular.forEach()从key动态创建角度对象,(Dynamically create angular object with key, value from angular.forEach())[2022-01-07]
你需要做的是parts[k] = value; 实际上,当你分配部分= {K:值}; ,这是这样的: parts["k"] = value; 所以你看到的不是取k的值,而是取k作为字符串,并将该值赋给这个字符串作为关键字段。 What you need to do is parts[k] = value; Actually when you assign parts = { k : value }; , This goes something like this : parts["k"] = value; ...是否可以将contenttype与非主键一起用于对象?(Is it possible to use contenttype with non primary key for the object?)[2023-11-27]
简短回答:不,不可能使GenericForeignKey使用除主键之外的任何其他目标字段。 主键在GenericForeignKey , GenericRelation和许多支持类(内联,相关描述符,那种东西)中进行了硬编码。 如果您确实想要使用UUID作为目标字段,那么您必须将UUID字段设置为目标模型上的主键,并使用与UUID兼容的类型作为Vote.object_id (例如CharField ,或者甚至是TextField - 这样你仍然可以指向具有整数主键的模型。 Short answer: No, ...创建自定义Comparer并将其传递给SortedList构造函数 : public class TypeComparer : Comparer { public override int Compare(MyKey x, MyKey y) { if (ReferenceEquals(x, y)) return 0; int typeX = int.MinValue; int typeY = int.MinValue ... 相关文章
更多- JavaScript 事件
- JavaScript 事件
- 解析JavaScript的事件机制
- HTML5服务器事件发送(Server-Sent Events)【HTML5教程 - 第十三篇】
- javascript 问题
- 请教javascript问题
- javascript的验证
- javascript 注释
- javascript 基本语法
- 传智播客_张孝祥_javascript教程教程
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)