javascript - 无法使用 jQuery 设置多个属性
问题描述
下面是 HTML 代码:
$('#shadowfax').hover(function () {
$('#horsename').attr({
class: 'display-5',
text: 'Ive been through the desert on a horse with no name. It felt good to be out of the rain. In the desert you can remember your name. Cause there aint no one for to give you no pain...'});
},
function () {
$('#horsename').text('A Horse with no name');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-sm">
<img id="shadowfax" src="images/horse.jpg" alt="ShadowFax">
</div>
<div class="row">
<div class="col-lg">
<p class="display-4" id="horsename">A Horse with no name</p>
</div>
</div>
我无法根据将鼠标悬停在 shadowfax 元素上来更改 horsename 元素的内容。
我正在使用 jQuery v3.3.1 和 Bootstrap v4。
谢谢
解决方案
您可以像这样简单地在 HTML 元素上使用事件 -
<div class="col-sm">
<img id="shadowfax" onmouseover='onMouseHover()' src="images/horse.jpg" alt="ShadowFax">
</div>
<div class="row">
<div class="col-lg">
<p class="display-4" onmouseout='onMouseOut()' id="horsename">A Horse with no name</p>
</div>
</div>
推荐阅读
- android - 无重组 [Jetpack Compose]
- python - 给定一个整数列表,找出不能表示为这些数字组合的最小整数(带 +、/ 和 *)
- java - 检查相机中的版本
- arrays - 在 numpy 数组中的第一个元素处添加零或创建数组的方法,将第一个位置保持为零
- vue.js - 如何在 Vue.js 中将文本与附件隔离开来
- css - 继续滚动时隐藏垂直滚动条
- r - 我无法在 R 中的 M1 Mac 上使用 keras 中的功能,它要求我安装 arm64e 版本的 miniconda3。该怎么办?
- sql - PostgreSQL 中多列的聚合操作
- javascript - 应用基于 div 类的过滤器
- c++ - 为什么 std::midpoint 不是指针的 noexcept ?