2016-12-01 37 views
0

enter image description here更改字符華氏攝氏度到字符

我要做到這一點,當我點擊飛輪海的性格,它會變成攝氏度character.But不行,怎麼做的?

<html lang="en"> 

$("a").click(function() { 
 
    if ($(this).text() == "&#8457;") { 
 
    $(this).html("&#8451;"); 
 
    } else { 
 
    $(this).html("&#8457;"); 
 
    } 
 
});
<script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css"> 
 
<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css"> 
 
<link rel="stylesheet" href="css/owfont-regular.css"> 
 
<a id="toggle" href="javascript:void(0)">&#8457;</a>

+1

'如果($(本)的.text()== '℉')' –

回答

3

這對我的作品

$("a").click(function() { 
 
    if ($(this).text() == "℉") { 
 
    $(this).text("℃"); 
 
    } else { 
 
    $(this).text("℉"); 
 
    } 
 
});
<script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script> 
 
<a id="toggle" href="javascript:void(0)">℉</a>

那麼,這是否

$("a").click(function() { 
 
    var temp = $(this).text(); 
 
    $(this).text(temp == "℉"?"℃":"℉"); 
 
});
<script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script> 
 
<a id="toggle" href="javascript:void(0)">℉</a>

+1

@actx:這是正確的比較(使用實際的Unicode字符):) –

+0

華氏字符可以直接輸入嗎? – Gaby

+0

@Gaby:有一個輸入任何Unicode字符的鍵序列。最壞的情況:Alt +(數字鍵盤)然後是字符的數值。 –