我想理解这段代码,因为我是初学者。主要是这些红色字体。他们正在获取哪个页面值?
$(function() {
$("#title").blur(function() { QuestionSuggestions(); });
});
function QuestionSuggestions() {
var s = $("#title").val();
if (s.length > 2 && !($("#title").hasClass('edit-field-overlayed'))) {
document.title = s + " - Stack Overflow";
$("#question-suggestions").load("/search/titles?like=" + escape(s));
}
}
最佳答案
function QuestionSuggestions() {
var s = $("#title").val(); // Here we take the value of element with ID "title"
// If the length of the title is bigger than 2 or
// the element doesn't have 'edit-field-overlayed' class
if (s.length > 2 && !($("#title").hasClass('edit-field-overlayed'))) {
// we set the title of the document as <title>[our old title] - Stack Overflow</title>
document.title = s + " - Stack Overflow";
// Load data from the server and place the returned HTML into the matched element.
$("#question-suggestions").load("/search/titles?like=" + escape(s));
}
}
如果 id title 的元素的标题长度超过 2,假设“我的标题”并且没有类“edit-field-overlayed”,我们将页面标题更改为“我的标题 - Stack Overflow”并加载 html/通过查询 URL http://yoursite.tld/search/titles?like=My%20title 元素“#question-suggestions”中的文本
关于javascript - 关于一段代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4022894/