HTML:
<input value='Rename' type='button' onclick='RenameGlobalPhase({$row['id']});'
<span id='renameGlobalPhase{$row['id']}'>" . $row['phase'] . "</span>
这是我的JS代码:
function RenameGlobalPhase(id)// {{{
{
var phase = $('#renameGlobalPhase' + id).html();
$('#renameGlobalPhase' + id).replaceWith("<input id='#renameGlobalPhase" + id + "' type='text' onblur='SaveNewPhaseName(" + id + ");' value='" + phase + "' />");
$('#renameGlobalPhase' + id).focus();
} // }}}
function SaveNewPhaseName(id)// {{{
{
var newPhase = $('#renameGlobalPhase' + id).val();
alert(newPhase);
$('#renameGlobalPhase' + id).replaceWith('<span>' + newPhase + '</span>');
} // }}}
因此,当用户点击上面的input
按钮时,我会将其旁边的span
转换为input
字段,以便用户重命名该值。在onblur
(从jQuery为新的input
字段新创建)中,我想保存新值并返回span
。
警报显示undefined
值。任何人都可以看到有什么问题吗?
答案 0 :(得分:4)
从#
id
更改
.replaceWith("<input id='#renameGlobalPhase" + id + "'
到
.replaceWith("<input id='renameGlobalPhase" + id + "'