Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 关于一段代码_Javascript_Jquery - Fatal编程技术网

Javascript 关于一段代码

Javascript 关于一段代码,javascript,jquery,Javascript,Jquery,我想了解这段代码,因为我是初学者。主要是这些红色字体。他们正在取哪一页的值 $(function() { $("#title").blur(function() { QuestionSuggestions(); }); }); function QuestionSuggestions() { var s = $("#title").val(); if (s.length > 2 && !($("#title"

我想了解这段代码,因为我是初学者。主要是这些红色字体。他们正在取哪一页的值

$(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));
    }
}
功能问题建议(){
var s=$(“#title”).val();//这里我们取ID为“title”的元素的值
//如果标题长度大于2或
//元素没有“编辑字段覆盖”类
if(s.length>2&&!($(“#title”).hasClass('edit-field-overlayed')){
//我们将文档的标题设置为[旧标题]-堆栈溢出
document.title=s+“-堆栈溢出”;
//从服务器加载数据,并将返回的HTML放入匹配的元素中。
$(“#问题建议”).load(“/search/titles?like=“+escape(s));
}
}
如果id为title的元素的标题长度大于2,则假设“我的标题”并且没有“编辑字段覆盖”类,我们将页面标题更改为“我的标题-堆栈溢出”,并通过查询URL将html/文本加载到元素“#问题建议”(question suggestions)(){ var s=$(“#title”).val();//这里我们取ID为“title”的元素的值 //如果标题长度大于2或 //元素没有“编辑字段覆盖”类 if(s.length>2&&!($(“#title”).hasClass('edit-field-overlayed')){ //我们将文档的标题设置为[旧标题]-堆栈溢出 document.title=s+“-堆栈溢出”; //从服务器加载数据,并将返回的HTML放入匹配的元素中。 $(“#问题建议”).load(“/search/titles?like=“+escape(s)); } }
如果id为title的元素的标题长度大于2,那么假设“我的标题”并且没有类“编辑字段覆盖”,我们将页面标题更改为“我的标题-堆栈溢出”,并通过查询URL将html/文本加载到元素“#问题建议”

,这看起来像jQuery代码。表达式
$(“#title”)
是对jQuery
$
函数的调用。它查找带有
id=“title”
的HTML标记,并在其周围包装一个实用程序对象
.blur
是该实用程序对象的一种方法,它提供了一个在鼠标离开相应元素时调用的函数


最好的办法是进入jQuery教程,如。

这看起来像jQuery代码。表达式
$(“#title”)
是对jQuery
$
函数的调用。它查找带有
id=“title”
的HTML标记,并在其周围包装一个实用程序对象
.blur
是该实用程序对象的一种方法,它提供了一个在鼠标离开相应元素时调用的函数


最好的办法是陷入jQuery教程中,比如。

发布的压缩成句子的代码是


“当id为'title'的字段模糊时,执行一个ajax查询,将该字段的内容作为参数传递”

已发布的压缩成句子的代码的peice是


“当id为'title'的字段模糊时,执行ajax查询,将该字段的内容作为参数传递”

2改进建议,它可以是
$(“#title”).blur(QuestionSuggestions)
并且不要使用
encode()
,使用
encodeURIComponent()
。2改进建议,可以是
$(“#title”).blur(问题建议)encode()
,使用
encodeURIComponent()
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));
        }
    }