我有个问题。看看下面的代码:
$(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();
});
});
现在和html:
<span>Click aici</span>
所以,这显然是有效的,直到 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();
});
});
要不就:
$(function () {
$('span').click(function () {
var input = $('<input />', {
'type': 'text',
'name': 'aname',
'value': $(this).html()
});
$(this).parent().append(input);
$(this).remove();
input.focus();
});
$('input').blur(function () {
$(this).parent().append($('<span />').html($(this).val()));
$(this).remove();
});
});
但这只是第一次。
请参阅此处的演示:http: //jsfiddle.net/hW3vk/ 因此,任何想法如何做到这一点将不胜感激。
先感谢您。