我知道我只是在阅读分配后感到困惑......
As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().
有人可以描述我如何解决下面的代码。当页面是静态的时,它会按预期工作。当对我的代码进行一般改进的评论也受到赞赏时,它不起作用,<!-- ajax fills this in -->
因为我对 jquery 真的很陌生。
谢谢,圣诞快乐!
<!DOCTYPE html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type='text/javascript'>
$(document).ready(function() {
$('form .edit').on( {
mouseenter: function() {
$(this).css({cursor:'pointer', color: 'red'});
},
mouseleave: function() {
$(this).css({cursor:'default', color: 'rgb(204, 204, 204)'});
},
click: function() {
var $t = $(this).parents('table').attr('id');
var $tr = '#'+ this.id;
var tData = $($tr +' > td');
$(tData).each(function () {
var td = '#'+ this.id;
var $th = $(td).closest('table').find('th').eq($(td).index()).text();
var html = $(this).html();
var input = $("<input id='"+$t+$tr+this.id+"' name='"+$t+"="+$th+"' />");
input.val(html);
$(this).html(input);
});
$('.edit').off();
}
});
});
</script>
</head>
<body>
<div>
<form id="userForm" method='get'>
<!-- ajax fills this in -->
<table class='table' id='user'>
<thead>
<tr class='head'>
<th>head 1</th>
<th>head 2</th>
</tr>
</thead>
<tfoot><tr></tr></tfoot>
<tbody>
<tr class='edit' id='1' title='click to edit'>
<td id='1a'>content 1a</td>
<td id='1b'>content 1b</td>
</tr>
<tr class='edit' id='0' title='click to edit'>
<td id='0a'>content 0a</td>
<td id='0b'>content 0b</td>
</tr>
</tbody>
</table>
<input class='ajaxSubmitAndReturn' type='submit' value='Submit' />
<input class='ajaxCancel' type='submit' value='Cancel' />
<!-- end of ajax -->
</form>
</div>
</body>
</html>