我有个问题.看下面的代码:
$(function () {
$('span').live('click', function () {
var input = $('<input />', {
'type': 'text',
'name': 'aname',
'value': $(this).html()
});
$(this).parent().append(input);
$(this).remove();
input.focus();
});
$('input').live('blur', function () {
$(this).parent().append($('<span />').html($(this).val()));
$(this).remove();
});
});
Run Code Online (Sandbox Code Playgroud)
和HTML现在:
<span>Click aici</span>
Run Code Online (Sandbox Code Playgroud)
所以,这显然适用于jquery 1.8.3,包括在内.在1.8.3 .live()被弃用之后,我们需要使用.on().所以代码变成:
$(function () {
$('span').on('click', function () {
var input = $('<input />', {
'type': 'text',
'name': 'aname',
'value': $(this).html()
});
$(this).parent().append(input);
$(this).remove();
input.focus();
});
$('input').on('blur', function () {
$(this).parent().append($('<span />').html($(this).val()));
$(this).remove();
});
});
Run Code Online (Sandbox Code Playgroud)
要不就:
$(function () {
$('span').click(function () { …Run Code Online (Sandbox Code Playgroud)