2012-11-07 18 views
1

下面是我的程序代碼如何更換jQuery的一個按鈕上的文字移動

<li class="ui-block-e"> 
    <a href="#login" data-transition="slide" data-role="button" data-theme="b" data-mini="true" id="UserLoginButtonP5" data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="span" class="ui-btn ui-btn-inline ui-mini ui-btn-up-b" data-inline="true"> 
    <span class="ui-btn-inner"> 
     <span class="ui-btn-text">Login</span> 
    </span> 
    </a> 
</li> 

jQuery的代碼替換

$("#UserLoginButtonP1").html("<span class='ui-btn-inner'><span class='ui-btn-text'>Logout</span></span>"); 

如何更換登錄註銷文本?

+1

下面是我的代碼...我沒有看到任何代碼。 – 2619

+0

代碼在哪裏? –

+0

現在,代碼是可見的。 – Max

回答

1
var test = $("#UserLoginButtonP5").html(); 
    test = test.replace('Login', 'Logout'); 
    $("#UserLoginButtonP5").html(test); 

工作演示jsfiddle

0

試試這個,

如果要替換按鈕上的文字,當點擊該按鈕意味着下面的代碼給定會奏效。

$("#btn1")​​​​​​.click(function(){ 
    $(this).val("Logout"); 
});​ 

Live Demo

在你的情況下,你想改變的span文本,所以你可以使用spanCSS類名的單擊事件一樣,

$(".ui-btn-text").bind('click',function(){ 
    $(this).html("Logout"); 
});​ 

Live Demo

(或)

要做到這一點在a點擊事件,下面的代碼給定會工作,

$("#UserLoginButtonP5").bind('click',function(){ 
    $("#UserLoginButtonP5 .ui-btn-text").html("Logout"); 
    //$("#UserLoginButtonP5 .ui-btn-text").text("Logout"); ('text' will be work also) 
});​ 

Live Demo

1

使用on()函數,而不是

$(document)​​​​​​.on('click', '"#UserLoginButtonP5"',function(){ 
    $(this).find('span').find('span').text("Logout"); 
});​ 

DEMO

+0

演示正在運行,但我們正在設計問題 – Patel

+0

那麼這是您的問題的解決方案之一。它取決於你使它適用於你的代碼。 – 2619

相關問題