用jQuery替换div的文本框 [英] replace textbox with div with jquery not working
本文介绍了用jQuery替换div的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
仅工作几秒钟,然后div再次消失:
It's just working for a few seconds and then the div disappears again:
$(document).ready(function () {
$("#done").click(function () {
$('#txtname').replaceWith(function () {
return '<div>' + $(this).val() + '</div>';
});
});
推荐答案
如果this
无效,您也可以使用ID
you can also use ID
if this
not works
$("#done").click(function() {
$('#txtname').replaceWith(function() {
return '<div>' + $("#txtname").val() + '</div>';
});
});
如果上面的方法不起作用,这是另一个示例
and here is another example if above not works
$("#done").click(function() {
$('#txtname').replaceWith('<div>' + $("#txtname").val() + '</div>');
});
这篇关于用jQuery替换div的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文