2010-08-23 64 views
1
$("#txtcode").autocomplete({ 
    minLength: 1, 
    source: "/AC/student.php?searchMode=''&Stno="+$("#txtcode").attr("value"), 
    select: function(event, ui) 
    { 
    var label= ui.item.label; 
    var value= ui.item.value; 
    var stuArr = label.split('-');    
    alert(stuArr [1]); 
    $('#tx_stname').val(stuArr [1].replace(/\$/g, "")); 

    } 
}); 

在上面的代碼中,當我說alert(stuArr [1]);如何去掉字體Jquery中的標籤

我從服務器端腳本獲取font標記<font size='1' color='green'>ABCDERT(Student name)</font>

如何刪除font標籤並在文本框中輸入「ABCDERT」名稱($('#tx_stname'))?

回答

4

你可以用它來把它當作一個元素,並使用.text()這樣的:

$('#tx_stname').val($(stuArr[1]).text()); 
+0

@nick:蔭抽到,我期待但在文本框中的值仍然conatains的 '$$' 的價值someValue中'',我用這個語句替換(stuArr [1] .replace(/ \ $/g,「」));。我如何替換文本字段$''中的'$$'SOME值''('#tx_stname ').val($(stuArr [1])。text.replace(/ \ $/g,「」));這是返回錯誤 – Someone 2010-08-23 16:11:00

+0

@Someone - 你需要在該調用中的'.text()',然後你所有設置的括號:) – 2010-08-23 16:16:26

+0

謝謝它解決了。但我該如何取代'有價值'。我該如何取代「某些價值」的單引號 – Someone 2010-08-23 16:20:38

0

嘗試:警報($(stuArr [1]),HTML());

例如:

<html> 
    <body> 
    <script src="http://code.jquery.com/jquery-1.4.2.min.js"> 
    </script> 

    <script> 
     var s = "<font>abc</font>"; 
     alert($(s).html()); 
    </script> 
</html> 
1

試試這個:

$('#tx_stname').val(stuArr [1].replace(/<[^>]+>/g, ""));