如何使用.text()
来修改文本,而不是选择元素中的其他元素?
var titleTextDiv = $('div#title-text'),
editTitleDiv = $('div#title-edit'),
editTitleInput = $('input[name=imageTitle]'),
editTitleLink = $('a#edit-title'),
saveTitleLink = $('a#save-title');
editTitleDiv.hide();
editTitleInput.val($.trim(titleTextDiv.text()));
editTitleLink.click(function() {
titleTextDiv.hide();
editTitleDiv.fadeIn('fast');
});
saveTitleLink.click(function() {
editTitleDiv.hide();
titleTextDiv.text($.trim(editTitleInput.val())).fadeIn('fast');
});
[ jsFIDDLE ] http://jsfiddle.net/2xMtQ/
目前,一切正常,除了标题更改为新值后,它会删除编辑/保存锚。为什么是这样?我能做些什么不同的事情?