【发布时间】:2013-04-28 18:01:39
【问题描述】:
我正在开发网络应用程序,我有这样一个要求,即每当用户在span 中单击text 时,我需要将convert 转换为input field 和on blur,我需要convert it back 再次跨越。所以我在我的一个jsp页面中使用了以下脚本。
Java 脚本:
<script type="text/javascript">
function covertSpan(id){
$('#'+id).click(function() {
var input = $("<input>", { val: $(this).text(),
type: "text" });
$(this).replaceWith(input);
input.select();
});
$('input').live('blur', function () {
var span=$("<span>", {text:$(this).val()});
$(this).replaceWith(span);
});
}
JSP 代码:
<span id="loadNumId" onmouseover="javascript:covertSpan(this.id);">5566</span>
现在我的问题是,只有第一次一切正常。我的意思是每当我单击first time 的跨度内的文本时,它都会转换为输入字段,然后onblur 会再次从输入字段转换回普通文本。但是如果再试一次就不行了。上面的脚本有什么问题?
【问题讨论】:
-
还有用于“就地编辑”的 jQuery 插件:stackoverflow.com/questions/708801/…
标签: javascript jquery jsp web-applications