割り当てを読んだ後、私はただ混乱していることを知っています...
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>