帮我把这段代码转换为原生js$(".ability-list .ability-item").hover(function () { $(".ability-list .ability-item").removeClass("active"); $(this).addClass("active"); });
时间: 2023-04-09 18:04:13 浏览: 67
可以这样转换:
var abilityItems = document.querySelectorAll(".ability-list .ability-item");
for (var i = 0; i < abilityItems.length; i++) {
abilityItems[i].addEventListener("mouseenter", function() {
for (var j = 0; j < abilityItems.length; j++) {
abilityItems[j].classList.remove("active");
}
this.classList.add("active");
});
}
相关问题
$.ajax原生js
好的,你的问题是关于 $.ajax 的原生 JavaScript 实现。在 JavaScript 中,我们可以使用 XMLHttpRequest 对象来实现 AJAX 请求。下面是一个简单的例子:
```javascript
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://example.com/api/data', true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText);
}
};
xhr.send();
```
在这个例子中,我们创建了一个 XMLHttpRequest 对象,并使用 open 方法指定了请求的方法、URL 和是否异步。然后,我们设置了 onreadystatechange 事件处理程序,当 readyState 属性变为 4(即请求完成)并且 status 属性为 200(即请求成功)时,我们输出响应文本。
使用原生js手写一个$.ajax()的封装
使用原生js手写一个$.ajax()的封装,可以参考jQuery中的$.ajax()的实现方式,自行编写一个XHR对象或使用XMLHttpRequest对象,实现类似jQuery封装方式的Ajax请求。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)