简体   繁体   中英

How can I use .text or .html to write special character?

I'm making a card game so I've made this script but I don't know why it doesn't output the symbols as ♥, but rather only ♥ as a string, anyone knows why?

$(document).ready(function() {

function makeCard(kind) {
    var
        card = $('<div>', { class: 'card' }),
        color = (kind == 'hearts' || kind == 'diams') ? 'red' : 'black',
        upper = $('<div>', { class: 'upper card-symbol ' + color, text: '\&' + kind + '\;' }),
        lower = $('<div>', { class: 'lower card-symbol ' + color, text: '\&' + kind + '\;' });

    card.append(upper).append(lower);
    card.appendTo('body');
}

makeCard('hearts');

});

You want html, not text:

http://jsfiddle.net/cxNqK/2/

    upper = $('<div>', {
        'class': 'upper card-symbol ' + color,
        html: '\&' + kind + '\;'
    }),
    lower = $('<div>', {
        'class': 'lower card-symbol ' + color,
        html: '\&' + kind + '\;'
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM