我正在尝试添加一个 href 链接到 jquery 附加。单击该链接会打开一个 ajax 模式。
这就是我所拥有的
$('<div/>').text(message.text).prepend($('<em/>')
.text('Opponent: '+ opponentName + ',' + ' ' + 'Game amount: ' + message.amount + ' ' + 'tokens,' + ' ' + 'Game: ' + message.game + ' ' + '<a href="#" data-toggle="ajaxModal">accept</a>')).appendTo($('#pendingChallenges'));
$('#pendingChallenges')[0].scrollTop = $(' #pendingChallenges')[0].scrollHeight;
最佳答案
您需要使用html而不是 text
将 html 字符串表示为 html 而不是 textcontent,这就是使用文本时发生的情况。
$('<div/>').text(message.text).prepend($('<em/>')
.html(...
关于javascript - 添加 jquery 附加链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20912902/