开发者

regarding a piece of code

i want to understand this piece of code as i m a beginner.Mostly these red color fonts. they are taking which page value?

$(function() {
        $("#title").blur(function() { QuestionSuggestions(); });    
});

function QuestionSuggestions() {
    var s = $("#title").val();            开发者_JS百科
    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));
        }
    }

If you element with id title has longer title than 2, lets say "My title" and there is no class "edit-field-overlayed" we change the page title to "My title - Stack Overflow" and load html/text in element "#question-suggestions" by querying the URL http://yoursite.tld/search/titles?like=My%20title


This looks like jQuery code. The expression $("#title") is a call to the jQuery $ function. It looks for the HTML tag with id="title" and wraps a utility object around it. .blur is a method of that utility object, which supplies a function to be called when the mouse moves off the corresponding element.

The best thing would be to get stuck into a jQuery tutorial like this one.


The peice of code posted, condensed to a sentence is

"When the field with id 'title' blurs, execute an ajax query passing the content of that field as a parameter"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜