Web Developer 面试题与答案
问题 11. How does CSS specificity work?
Specificity determines which CSS rule takes precedence when multiple conflicting rules target the same element.
Example:
div#myId {
color: blue;
}
#myId {
color: red;
}
问题 12. What is AJAX, and how does it work?
AJAX (Asynchronous JavaScript and XML) allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes.
Example:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.example.com/data', true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText);
}
};
xhr.send();
问题 13. What is responsive web design?
Responsive web design ensures that web applications render well on various devices and window or screen sizes.
Example:
@media screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
问题 14. Explain the concept of event delegation in JavaScript.
Event delegation involves using a single event listener to manage all related events for a specific type, reducing the number of event listeners.
Example:
document.getElementById('parentElement').addEventListener('click', function(event) {
if (event.target.tagName === 'BUTTON') {
console.log('Button clicked!');
}
});
问题 15. What is the purpose of the 'this' keyword in JavaScript?
The 'this' keyword refers to the current execution context and allows access to properties and methods of the current object.
Example:
const person = {
name: 'John',
greet: function() {
console.log('Hello, ' + this.name + '!');
}
};
person.greet();
用户评价最有帮助的内容: