/* * Schedule an invocation or invocations of f() in the future. * Wait start milliseconds, then call f() every interval milliseconds, * stopping after a total of start+end milliseconds. * If interval is specified but end is omitted, then never stop invoking f. * If interval and end are omitted, then just invoke f once after start ms. * If only f is specified, behave as if start was 0. * Note that the call to invoke() does not block: it returns right away. */ functioninvoke(f, start, interval, end) { if (!start) start = 0; // Default to 0 ms if (arguments.length <= 2) // Single-invocation case setTimeout(f, start); // Single invocation after start ms. else { // Multiple invocation case setTimeout(repeat, start); // Repetitions begin in start ms functionrepeat() { // Invoked by the timeout above var h = setInterval(f, interval); // Invoke f every interval ms. // And stop invoking after end ms, if end is defined if (end) setTimeout(function() { clearInterval(h); }, end); } } }
/* * This function parses ampersand-separated name=value argument pairs from * the query string of the URL. It stores the name=value pairs in * properties of an object and returns that object. Use it like this: * * var args = urlArgs(); // Parse args from URL * var q = args.q || ""; // Use argument, if defined, or a default value * var n = args.n ? parseInt(args.n) : 10; */ functionurlArgs() { var args = {}; // Start with an empty object var query = location.search.substring(1); // Get query string, minus '?' var pairs = query.split("&"); // Split at ampersands for (var i = 0; i < pairs.length; i++) { // For each fragment var pos = pairs[i].indexOf('='); // Look for "name=value" if (pos == -1) continue; // If not found, skip it var name = pairs[i].substring(0, pos); // Extract the name var value = pairs[i].substring(pos + 1); // Extract the value value = decodeURIComponent(value); // Decode the value args[name] = value; // Store as a property } return args; // Return the parsed arguments }
location = "http://www.oreilly.com"; // Go buy some books! location = "page2.html"; // Load the next page /** * #top不存在时,浏览器跳到文档开始处 */ location = "#top"; // Jump to the top of the document location.search = "?page=" + (pagenum+1); // load the next page
<!--[if IE 6]> This content is actually inside an HTML comment. It will only be displayed in IE 6. <![endif]--> <!--[if lte IE 7]> This content will only be displayed by IE 5, 6 and 7 and earlier. lte stands for "less than or equal". You can also use "lt", "gt" and "gte". <![endif]--> <!--[if !IE]> <--> This is normal HTML content, but IE will not display it because of the comment above and the comment below. <!--> <![endif]--> This is normal content, displayed by all browsers.
/*@cc_on @if (@_jscript) // This code is inside a JS comment but is executed in IE. alert("In IE"); @end @*/
/*@cc_on @if (@_jscript) // This code is inside a conditional comment, which is also a // regular JavaScript comment. IE runs it but other browsers ignore it. alert('You are using Internet Explorer); @else*/ // This code is no longer inside a JavaScript comment, but is still // inside the IE conditional comment. This means that all browsers // except IE will run this code. alert('You are not using Internet Explorer'); /*@end @*/