JQuery 1.7.1中的代码在2.0.2中不起作用
Code in JQuery 1.7.1 not working in 2.0.2
当点击添加行按钮时,我正试图克隆最后一行,如下所示,此代码在1.7.1 jquery中运行良好,但如果我引用2.0.2,则无法运行
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
那么它就不起作用了。
我添加了jquery-migrate-1.1.js,但仍然没有用。
请帮助解决。
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<table id="advFilterTable" class="table-filter">
<tbody>
<tr>
<td>
<select id="advFilterColumn1" name="advFilterColumn1" class="chzn-select filter-column" data-placeholder="Select Column" style="width: 120px;">
<option value=SupportDesciption>Support Desciption</option>
<option value=CostCentre.CostCentreCode>Cost Centre</option>
<option value=AdditionalPropertyValue.value>System Roles</option>
<option value=AdditionalProperty.Key>System Role Type</option>
</select>
</td>
<td>
<select id="advFilterOperand1" name="advFilterOperand1" class="chzn-select filter-operand" data-placeholder="Select Operand" style="width: 120px;">
<option value=Equals>Equals</option>
<option value=GreaterThan>GreaterThan</option>
<option value=LessThan>LessThan</option>
<option value=GreaterThanOrEqual>GreaterThanOrEqual</option>
<option value=LessThanOrEqual>LessThanOrEqual</option>
<option value=Contains>Contains</option>
<option value=StartsWith>StartsWith</option>
<option value=EndsWith>EndsWith</option>
</select>
</td>
<td>
<input id="advFilterText1" name="advFilterText1" class="filter-text" style="height: 17px; margin-bottom: 8px" type="text" value=""></input>
</td>
<td>
<button class="btn delete-filter" id="advFilterbtn1" name="advFilterbtn1" style="margin-bottom: 8px"><i class="icon-minus"></i></button>
</td>
</tr>
</tbody>
</table>
<button class="add-filter">Add Row</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(".add-filter").live('click', function(event) {
// clone the last row in the table
var $tr = $('.table-filter').find("tbody tr:last").clone();
// get the name attribute for the input and select fields
$tr.find("input,select").attr("name", function() {
// break the field name and it's number into two parts
var parts = this.id.match(/('D+)('d+)$/);
if (parts != null) {
// create a unique name for the new field by incrementing
// the number for the previous field by 1
return parts[1] + ++parts[2];
}
return rollDice();
// repeat for id attributes
}).attr("id", function() {
var parts = this.id.match(/('D+)('d+)$/);
if (parts != null) {
return parts[1] + ++parts[2];
}
return rollDice();
});
$('.table-filter').find("tbody tr:last").after($tr);
});
</script>
</body>
</html>
扩展Lwyrn的答案,
更改
$(".add-filter").live('click', function(event) {
至
$(document.body).on('click', '.add-filter', function(event) {
live函数在jquery 1.7中被弃用,在1.9中被完全删除使用.click而不是.live
相关文章:
- ng-view 中的脚本在从文件引用时不起作用(JQuery 在角度之前加载)
- 转换效果不起作用jquery
- 淡入淡出和AppendTo不起作用-jQuery
- 变量计算不起作用(jquery/javascript)
- 更改事件不起作用 jQuery 自动完成
- 倒计时不起作用 jquery
- ajax 响应包括 image,onClick 事件对图像不起作用 jQuery
- 从JavaScript添加html,但不起作用jQuery切换功能
- 简单的工具提示插件 - 点击选项不起作用 - jQuery
- 图像滑块不起作用(jquery)- Rails 3项目
- 触发单击事件不起作用 jquery
- 动态创建的 li 点击事件不起作用 jQuery
- Jquery验证不起作用.Jquery-Javascript
- JavaScript生成的元素不起作用-jQuery
- 事件委派不起作用jquery
- 类选择器在追加后不起作用 (JQuery)
- 为什么这个变量不起作用?Jquery
- 首先,渐变有时似乎不起作用(jquery)
- 有什么原因吗('img')加载不起作用(jQuery)
- 更改不起作用jQuery