javascript - 关于一段代码

标签 javascript jquery

我想理解这段代码,因为我是初学者。主要是这些红色字体。他们正在获取哪个页面值?

$(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/

相关文章:

javascript - 使用 Jquery 有条件地将类添加到图像

javascript - 访问对象 jquery 中的数组时出现问题

jquery - 使用 jQuery 文本字段选择全部/放置光标

javascript - Jquery (Window).Resize() 调用函数不正确

javascript - 操作网页中的部分 - 创建、扩展

javascript - 使用 SkelJS 的断点 - 调整宽屏显示器?

javascript - 最佳实践 - ASP.NET 合并所有 JavaScript 输出

javascript - d3.js 强制定向图不起作用

javascript - jQuery 数据表 : Set a search filter for a named column upon initialization

jquery - SlickGrid 在鼠标悬停时更改行背景颜色