jquery的clone方法bug的修复
最近发现jquery的clone的bug,textarea和select的jquery的clone方法有问题,textarea和select的值clone的时候会丢掉,在网上发现一个插件,下载地址如下:https://github.com/spencertipping/jquery.fix.clone/blob/master/jquery.fix.clone.js,上不了的可以看下代码,比较简单。就是在clone的时候将val再重新赋值一下,如果知道这个了,也可以不用这个插件,自己写。
// Textarea and select clone() bug workaround | Spencer Tipping
// Licensed under the terms of the MIT source code license // Motivation.
// jQuery's clone() method works in most cases, but it fails to copy the value of textareas and select elements. This patch replaces jQuery's clone() method with a wrapper that fills in the
// values after the fact. // An interesting error case submitted by Piotr Przybył: If two <select> options had the same value, the clone() method would select the wrong one in the cloned box. The fix, suggested by Piotr
// and implemented here, is to use the selectedIndex property on the <select> box itself rather than relying on jQuery's value-based val(). (function (original) {
jQuery.fn.clone = function () {
var result = original.apply(this, arguments),
my_textareas = this.find('textarea').add(this.filter('textarea')),
result_textareas = result.find('textarea').add(result.filter('textarea')),
my_selects = this.find('select').add(this.filter('select')),
result_selects = result.find('select').add(result.filter('select')); for (var i = 0, l = my_textareas.length; i < l; ++i) $(result_textareas[i]).val($(my_textareas[i]).val());
for (var i = 0, l = my_selects.length; i < l; ++i) result_selects[i].selectedIndex = my_selects[i].selectedIndex; return result;
};
}) (jQuery.fn.clone);
jquery的clone方法bug的修复的更多相关文章
- jquery的clone方法bug的修复select,textarea的值丢失
项目中多次使用了iframe,但是操作起来是比较麻烦,项目中的现实情况是最外面是一个form,里面嵌套一个iframe,下面是一个其他的数据,在form提交的时候将iframe的数据和其他的数据一块提 ...
- jquery的clone方法 于textarea和select的bug修复
在使用jquery的clone方法时,textarea和select的值clone的时候会丢掉,这可能是这个方法的一个BUG.解决办法就是在clone的时候将val再重新赋值一下. 引入到你要用的cl ...
- jquery的clone方法应用于textarea和select的bug修复不能copy值,clone id重复的解决
textarea和select的值clone的时候会丢掉,在clone的时候将val再重新赋值一下,如果知道这个了就简单了, 测试发现,textarea和select的jquery的clone方法有问 ...
- jquery的clone办法bug修复
发现测试,textarea和select的jquery的clone有问题的方法,textarea和select值clone时间会输.这是发现jquery一个bug,上不了的能够看下代码.比較简单.就是 ...
- jquery之clone()方法详解
clone()函数用于克隆当前匹配元素集合的一个副本,并以jQuery对象的形式返回.你也可以简单地理解为:克隆当前jQuery对象. 你还可以指定是否复制这些匹配元素(甚至它们的子元素)的附加数据( ...
- jquery clone方法
引用自http://www.w3school.com.cn/tiy/t.asp?f=jquery_manipulation_clone <html> <head> <sc ...
- JQuery1.72中二个Bug,formhtml()方法与clone()方法的二个Bug进行重写
//扩展方法$.formhtml,解决firefox中html()方法得不到修改input值后的html代码(function ($) { var oldHTML = $.fn.html; ...
- 表单使用clone方法后, 原有select无法生效
textarea和select的值clone的时候会丢掉,在clone的时候将val再重新赋值一下,如果知道这个了就加单了 测试发现,textarea和select的jquery的clone方法有 ...
- 关于jQuery的append方法不能多次添加同一个DOM元素的解决方法
资料来自:https://segmentfault.com/q/1010000007677851?_ea=1419689 append()方法在jQuery中是使用appendChild()实现的,实 ...
随机推荐
- UVALive 5713 Qin Shi Huang's National Road System秦始皇修路(MST,最小瓶颈路)
题意: 秦始皇要在n个城市之间修路,而徐福声可以用法术位秦始皇免费修1条路,每个城市还有人口数,现要求徐福声所修之路的两城市的人口数之和A尽量大,而使n个城市互通需要修的路长B尽量短,从而使得A/B最 ...
- 【英语】Bingo口语笔记(22) - Talk系列
talk back 顶嘴 talk somebody in to something 劝某人做某事 tal somebody out of something 劝某人不做某事
- 【解题报告】POJ-1108 Split Windows
原题地址:http://poj.org/problem?id=1108 ============================== 题目大意: 一棵树表示一个窗口,它的叶子节点都是大写字母,非叶子节 ...
- ubuntu eclipse 安装svn
1.helper->install new software 在弹出的窗口中work with 输入http://subclipse.tigris.org/update_1.6.x 2.下面窗口 ...
- Bootstrap学习笔记上(带源码)
阅读目录 排版 表单 网格系统 菜单.按钮 做好笔记方便日后查阅o(╯□╰)o bootstrap简介: ☑ 简单灵活可用于架构流行的用户界面和交互接口的html.css.javascript工具集 ...
- [转] DateTime.Now.ToString()的较为全面的使用介绍
原文地址 DateTime.Now.ToString() 用法 具体的操作如下面的两段代码 //2008年4月24日 System.DateTime.Now.ToString("D" ...
- 使用 XML 实现 REST 式的 SOA
什么是 SOA? 如果公司有大量应用程序,这些程序供不同部门的承担不同责任的职员使用,那么就适合使用面向服务体系结构(Service Oriented Architecture,SOA).这些应用程序 ...
- 五种开源协议的比较(BSD,Apache,GPL,LGPL,MIT)(整理)
BSD开源协议(original BSD license.FreeBSD license.Original BSD license) BSD开源协议是一个给于使用者很大自由的协议.基本上使用者可 ...
- [转]linux 下使用dump和restore命令
转自:http://blog.sina.com.cn/s/blog_63eb479a01011sdu.html dump 支持分卷和增量备份(所谓增量备份是指备份最近一次备份以来修改过的文件,也称差异 ...
- Selenium2Library系列 keywords 之 _SelectElementKeywords
# 公有方法 (1)get_list_items(self, locator) 返回labels集合 _get_select_list_options(self, select_list_or_lo ...