javascript - Ajax 调用 - JS 不正确的表示法
问题描述
我们可以使用 each 方法来迭代 JavaScript 数组。
// To use the each() function, we first need to convert our JavaScript object into a jQuery object
// using the $() function.
// The function passed as a parameter to the each method is a "callback" and it specifies what to do
// with each element.
//
// Remember that a callback is a function passed into another function as an argument,
// which is then invoked inside the outer function to complete some kind of routine or action.
let url = 'https://google.com'
$.ajax(url).done(load);
function load(data) {
console.log(data)
$(document.body).append('<img>');
$('img').attr('src', data.url)
$('img').on('click', refresh)
}
function refresh() {
$(this).remove();
$.ajax(url).done(load);
}
$(people).each(function(index, value) {
console.log("Exploring jQuery each method: ", index, value);
let staffItem = $('<li>' + personToString(value) + '</li>');
$('#directory').append(staffItem);
staffItem.on("mouseover", highlightStaff)
.on("mouseout", removeHighlight)
.on("click", addStaff);
});
function highlightStaff() {
$(this).addClass("hoverBackground");
}
function removeHighlight() {
$(this).removeClass("hoverBackground");
}
function addStaff() {
let selectedStaff = $(this).clone();
selectedStaff.removeClass("hoverBackground");
$("#selected-staff").append(selectedStaff);
selectedStaff
.on("mouseover", highlightStaff)
.on("mouseout", removeHighlight)
.on("click", removeStaff);
}
{
$(this).remove();
}
解决方案
推荐阅读
- java - 从 Spring 3.2 迁移到 Spring 4.3
- matplotlib - Matplotlib 旋转 3d 对象
- python - 如果从未在测试中直接调用函数,是否可以制作 pytest 报告?
- apache-kafka - Kafka + Spring Batch Listener Flush Batch
- powershell - 以登录用户身份运行 powershell 脚本
- ios - Issue in updating value from `UserDefaults` in Swift
- macos - 是否可以在当前 Finder 位置打开 iTerm
- java - 如何使用 selenium webdriver 压缩和通过电子邮件发送在黄瓜中生成的测试报告
- java - 如何将 JSON 字符串转换为对象的 Arraylist
- javascript - ember-electron:为 ember 和电子应用程序编译的不同资产