gpt4 book ai didi

javascript - 如果将鼠标悬停在文本上,将文本更改为其他内容

转载 作者:行者123 更新时间:2023-11-29 10:31:09 24 4
gpt4 key购买 nike

我正在尝试制作一个表格,如果您将鼠标悬停在部分数据上,它会将数据值更改为其他值。如果您将鼠标取下,它将恢复原状。

问题是,如果它有多个具有正确数据的条目,它将更改每个 ID/类名称集所在的条目,但我希望它只与悬停的条目一起使用。我尝试用 $(this) 来做,但没有成功。

$(document).ready(function() {
$('.wep-data').on({
mouseenter: function() {
document.getElementById("1").style.display = "none";
document.getElementById("3").style.display = "none";
document.getElementById("2").colSpan = "3";
$('.wep-data').html('9999k');
$('.wep-data').first().html('');
$('.wep-data').last().html('');
$('.wep-data').css('border-right', '2px solid #ccc');
$('.wep-data').css('border-left', '2px solid #ccc');
},
mouseleave: function() {
document.getElementById("1").style.display = "table-cell";
document.getElementById("3").style.display = "table-cell";
document.getElementById("2").colSpan = "1";
$('.wep-data').html('0');
$('.wep-data').first().html('0');
$('.wep-data').last().html('0');
$('.wep-data').css('border-right', '2px solid #ccc');
$('.wep-data').css('border-left', '2px solid #ccc');
}
});
});
.weapon-type-selection{
text-shadow: 1px 1px 1px #881812, 1px -1px 1px #881812, -1px 1px 1px #881812, -1px -1px 1px #881812;
cursor: pointer;
color: white;
font-size: 18px;
margin-top: 14px;
margin-bottom: 10px;
}
table, th, td {
margin: 5px;
font-size: 18px;
}

th{
border-bottom: 2px solid #ccc;
border-right: 2px solid #ccc;
}

td{
border-bottom: 2px solid #ccc;
border-right: 2px solid #ccc;
border-left: 2px solid #ccc;
}
.weapons{
height: 670px;
}
.wep-name{
width: 295px;
}
.wep-data{
width: 40px;
text-align: center;
padding: 5px;
}
.wep-cond{
text-align: center;
}
.weapon-list{
margin: 10px;
color: #2b2825;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="borderBox weapons">
<div class="weapon-list">
<table>
<tr>
<th>Name</th>
<th colspan="3" class="wep-cond">Brand New</th>
<th colspan="3" class="wep-cond">New</th>
<th colspan="3" class="wep-cond">Poor</th>
<th colspan="3" class="wep-cond">Low-Quality</th>
<th colspan="3" class="wep-cond">Rotten</th>
</tr>
<tr>
<td class="wep-name">Sword</td>
<td id="1" class="wep-data">0</td>
<td id="2" class="wep-data">0</td>
<td id="3" class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
</tr>
<tr>
<td class="wep-name">Bow</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
</tr>
<tr>
<td class="wep-name">Knife</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
</tr>
</table>
</div>
</div>
</div>

最佳答案

试试这个:

$(document).ready(function() {
var getElementBlock = function(el) {
var $el = $(el),
$allTds = $el.parent().find("td:not(:first)"),
index = $el.index();
c1 = (index - 1),
c2 = Math.floor(c1 / 3) * 3,
$els = $allTds.slice(c2, (c2 + 3));

return $els;
};

$('.wep-data').on({
mouseenter: function() {
var $els = getElementBlock(this);
$els.filter(":not(:eq(0))").hide();
$els.filter(":eq(0)").attr("colspan", 3);

$('.wep-data-fn').html('9999k');
$('.wep-data-fn').first().html('');
$('.wep-data-fn').last().html('');
$('.wep-data-fn').css('border-right', '2px solid #ccc');
$('.wep-data-fn').css('border-left', '2px solid #ccc');
},
mouseleave: function() {
var $els = getElementBlock(this);
$els.filter(":not(:eq(0))").show();
$els.filter(":eq(0)").removeAttr("colspan");

$('.wep-data-fn').html('0');
$('.wep-data-fn').first().html('0');
$('.wep-data-fn').last().html('0');
$('.wep-data-fn').css('border-right', '2px solid #ccc');
$('.wep-data-fn').css('border-left', '2px solid #ccc');
}
});
});
.weapon-type-selection{
text-shadow: 1px 1px 1px #881812, 1px -1px 1px #881812, -1px 1px 1px #881812, -1px -1px 1px #881812;
cursor: pointer;
color: white;
font-size: 18px;
margin-top: 14px;
margin-bottom: 10px;
}
table, th, td {
margin: 5px;
font-size: 18px;
}

th{
border-bottom: 2px solid #ccc;
border-right: 2px solid #ccc;
}

td{
border-bottom: 2px solid #ccc;
border-right: 2px solid #ccc;
border-left: 2px solid #ccc;
}
.weapons{
height: 670px;
}
.wep-name{
width: 295px;
}
.wep-data{
width: 40px;
text-align: center;
padding: 5px;
}
.wep-cond{
text-align: center;
}
.weapon-list{
margin: 10px;
color: #2b2825;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="borderBox weapons">
<div class="weapon-list">
<table>
<tr>
<th>Name</th>
<th colspan="3" class="wep-cond">Brand New</th>
<th colspan="3" class="wep-cond">New</th>
<th colspan="3" class="wep-cond">Poor</th>
<th colspan="3" class="wep-cond">Low-Quality</th>
<th colspan="3" class="wep-cond">Rotten</th>
</tr>
<tr>
<td class="wep-name">Sword</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
</tr>
<tr>
<td class="wep-name">Bow</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
</tr>
<tr>
<td class="wep-name">Knife</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
<td class="wep-data">0</td>
</tr>
</table>
</div>
</div>
</div>

关于javascript - 如果将鼠标悬停在文本上,将文本更改为其他内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45740798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com