簡體   English   中英

使用jQuery在span中添加✔刻度線

[英]Using jQuery to add a ✔ tick mark in span

這個問題我得知復選標記是代碼✔ (0x2714 [HTML decimal: ✔]) 我知道你通過執行$('#spanid').text(texthere);使用jQuery向span添加文本$('#spanid').text(texthere); 我想在跨度上添加復選標記。

我做到了

$('#spanid').text(✔); //This errors on the `&`
$('#spanid').text(#10004); //This results in `Unexpected token ILLEGAL

這樣做的正確方法是什么?

使用.html() 另外,將值括在引號中。

$('#spanid').html('✔');

.text()會將輸入轉換為文本字符串。 .html()轉換為HTML字符串/內容,可以看到編碼的字符。

小提琴演示

或者如果你已經擁有角色.text()就可以了;

$('#spanid').text('✔');

我會做的是:

$('#spanid').addClass('check');

並添加CSS;

.check:after {
  content: '(what ever the code for the check mark is)';
}

或者,您可以使用String.fromCharCode創建復選標記:

$('#spanid').text(String.fromCharCode(10004));

嘗試

$('#spanid').html ('✔');

而不是text() text函數轉義字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM