我有以下HTML
<h1 class="headerLogo headerLogoWith"><span class="headvendnametext">Pick</span><br>
<i class="headloctext">Location Name <span class="headscreentext">ScreenName</span></i></h1>
我想只替换Locationame部分和ScreenName文本,
我试过这种方式
$('.headloctext').text('Mylocation');
$('.headscreentext').text('myscreen');
当我跑上面时,屏幕部分完全丢失
http://jsfiddle.net/d72wvjjn/2/
请告诉我如何解决问题??
答案 0 :(得分:4)
var headScreenText = $('.headscreentext');
$('.headloctext').text('Some new text ').append(headScreenText);
<强> Demo 强>
答案 1 :(得分:1)
HTML
<h1 class="headerLogo headerLogoWith"><span class="headvendnametext">Pick</span><br>
<i><span class="headloctext">Location Name</span> <span class="headscreentext">ScreenName</span></i></h1>
那应该解决问题。很简单,是吗?