我有此代码,它需要一个数字并将该数字生成到卡中 我的问题是代码生成2张卡,而不是一张 在第一张卡片中,我开始时会看到一个“>,并且当我将鼠标悬停在上面时说:div class = 并且工具提示不起作用
结果必须是带有详细信息的卡片,如果您使用工具提示,则会带您获得更多详细信息
$(window).load(function() {
function make_card_list(card, el) {
var html = '';
html += '<div class="card" id="card_' + card.id + '">';
html += '<span class="card_id">#superhero' + card.id + '</span>';
html += '<div class="card_header">';
html += '<span data-name="name">' + card.name + '</span>';
html += '</div>';
html += '<div class="abilities-details">' + card.abilities + '</div>';
html += '<div data-tooltip="' + '" class="card_picture" data-name="img" style="background-image: url(' + card.img + ');text-align:center;color:black;line-height: 150px;">';
var poster_data = $(el).parent().parent().find('.postprofile textarea').val();
if (poster_data) {
poster_data = JSON.parse(poster_data);
if (jQuery.inArray(Number(card.id), poster_data.cards) == -1) {
html += '<div class="nocard">This card does not exit.</div>';
}
}
html += '</div>';
html += '<div class="card_text">';
html += '<span data-name="txt">';
html += card.txt;
html += '</span>';
html += '</div>';
html += '<div class="abilities"></div>';
html += '<div class="card_bottom card_stats">';
html += '<div class="card_stats_inside">';
if (card.strength != "") {
html += '<p>Strength: <span data-name="strength">' + card.strength + '</span></p>';
};
if (card.energy != "") {
html += '<p>Energy: <span data-name="damage">' + card.energy + '</span></p>';
};
if (card.skills != "") {
html += '<p>Skills: <span data-name="damage">' + card.skills + '</span></p>';
};
if (card.speed != "") {
html += '<p>Speed: <span data-name="damage">' + card.speed + '</span></p>';
};
html += '</div>';
html += '</div>';
if (card.type == 16 || card.type == 14 || card.type == 31 || card.type == 27) {
html += '<div class="card_bottom card_slots" style="width:335px;">';
html += '<div class="card_slots_inside">';
if (card.inv > 0) {
for (var i = 0; i < 10; i++) {
if (i < card.inv) {
html += '<span style="background:#9d1717;" class="card_inv"></span>';
} else {
html += '<span class="card_inv"></span>';
}
}
}
html += '<span style="background: #57b371;" class="card_slot"></span>';
} else {
html += '<div class="card_bottom card_middle">';
html += '<div class="card_stats_inside">';
if (card.enemies != "") {
html += '<p>Enemies: <span data-name="enemies">' + card.enemies + '</span></p>';
};
html += '</div>';
html += '</div>';
html += '<div class="card_bottom card_slots">';
html += '<div class="card_slots_inside">';
if (Number(card.slot) > 0) {
for (var i = 0; i < 5; i++) {
if (i < card.slot) {
html += '<span style="background: #57b371;" class="card_slot"></span>';
} else {
html += '<span class="card_slot"></span>';
}
}
}
}
html += '</div>';
html += '</div>';
html += '</div>';
if (card.type == 16 || card.type == 14 || card.type == 31 || card.type == 27) {
$('#card_' + card.id + ' .card_middle').remove();
$('#card_' + card.id + ' .card_slots').css('width', '335px');
}
return html;
}
//======== CARD MANAGER ==========
function sortCards(ar, s, t) {
var results = [];
var f = ar.find(function(ele) {
if (ele[t] == s) {
results.push(ele);
}
});
return results;
}
$(".pun .entry-content, .pravilacontent div").each(function() {
var h = '';
$('img[src^="#card"]', this).each(function() {
var npccard = $(this).attr('src');
if (npccard != null) {
}
});
if (h != '') {
$(this).parent().parent().find('.topic-title a').text('NPC Attack');
$(this).html(h);
}
var content = $(this).html();
var el = $(this);
content = content.replace(/#myluckynumberis(\d+)/g, function(match, capture) {
if (!cards[capture]) {
return "myluckynumberis #" + capture + " does not exists";
return false;
}
return make_card_list(sortCards(cards, capture, "id")[0], el);
});
$(this).html(content);
});
});
$(function() {
//Indicate here the version of your forum.
var version = "punbb";
if (version.toLowerCase() == "phpbb2") {
$(".postdetails span[class='staff']").closest('.postdetails').parent('td').next('td').addClass("staffbg");
} else if (version.toLowerCase() == "phpbb3") {
$(".postprofile span[class='staff']").closest('.postprofile').prev('.postbody').addClass("staffbg");
} else if (version.toLowerCase() == "punbb") {
$(".user-info span[class='staff']").closest('.postmain').addClass("staffbg");
} else if (version.toLowerCase() == "invision") {
$(".postprofile span[class='staff']").closest('.post-container').addClass("staffbg");
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>