jQuery的更改div文本 [英] jquery change div text
问题描述
'<div id="'+div_id+'" class="widget" style="height:60px;width:110px">\n\
<div class="widget-head ui-widget-header" style="cursor:move;height:20px;width:130px">'+
'<span id="'+span_id+'" style="float:right; cursor:pointer" class="dialog_link ui-icon ui-icon-newwin ui-icon-pencil"></span>' +
dialog_title+'</div></div>
我使用上面的字符串构造了一个div.经过一些处理..我必须在上面的div中更改dialog_title.我正在尝试使用下面的代码
I have a div constructed using the above string. After some processing..I have to change the dialog_title in the above div. I am trying to do it with the following code
$('#'+div_id+' .widget-head').text("new dialog title");
这会更改对话框标题..它会删除用于打开对话框的span元素.
While this changes the dialog title..it removes the span element which is used to open a dialog box.
我尝试使用带有新对话框标题的字符串来代替replaceWith方法.但这显示了标题的NaN和无法单击的跨度(是否禁用了事件?)
I tried to the replaceWith method with a string with new dialog title..but that shows NaN for title and the span though visible cant be clicked(are events disabled?)
如何在不失去跨度和单击能力的情况下更改文本.
How do I change the text without losing the span and ability to click it.
谢谢.
推荐答案
将标题放在自己的跨度中.
Put the title in its own span.
<span id="dialog_title_span">'+dialog_title+'</span>
$('#dialog_title_span').text("new dialog title");
这篇关于jQuery的更改div文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!