JS (JQ) Some common grammar

JavaScript-related

Simple front page is written in Java back-end development of essential skills. The following summarizes some of the common JS grammar, ready for use.

Part of the grammar

  • Determining whether non-numeric: isNaN ()

true is not a number; false is digital

  • 定义一个对象: Var {obj = attribute name: attribute value, ...}
  • 遍历一个对象: For (variable name in the custom set) {}
  • 数组创建: Var custom array name = [1, ...]
  • Through the array: for (var I = 0; I <array name .length; I ++) {}
  • Natural array sort: .sort ()
  • Inserting the end of an array element: . Push ()
  • Delete the last element ( 长度减一): .prop ()
  • Removes the specified location element ( 长度不变): the Delete array name [subscript]
  • Remove the first element of the array, and returns the first element of :: shift( )

Event-related

  • Page has been loaded trigger: the onload
  • Window trigger when leaving: onunload
    Related Forms
  • Current element loses focus: onblur
  • The current element receives the focus: the onfocus
  • Cancel event bubbling: cancelBubble to true =

DOM-related

  • Operation tag body content: the innerText
  • Operation various labels comprising: the innerHTML
  • Current time label object: the this

BOM-related

BOM :一组浏览器相关的内置对象以及他们的函数和属性

  • Open a new window: window.open ( "url")
  • Close: use Close ()
  • Alert box: Alert ( "...")
  • Confirmation box: Confirm The ( "...")
  • Prompt input box: prompt ( "...")
  • 定时器setTimeout(fun,time)

After time milliseconds, performs a function fun

  • Remove the timer: clearTimeout ( 引用名)
  • 周期定时器setInterval(fun,time)

Every time milliseconds, performs a function fun

  • Removing cycle timer: clearInterval ( 引用名)
  • 跳转location.href = "url"
    history characteristics
  • Return Previous: history.back ()
  • Forward: history.forward ()
  • GM:history.go(num)

num negative values reverse
num 0 means refresh
num is a positive number indicates progress

jQuery related

https://www.w3school.com.cn/jquery/jquery_ref_events.asp

Part of the grammar

  • General: $ (the DOM objects)
  • 遍历数组.each(function(idx){ });
  • Operational attributes:.prop("属性名",“值”)
  • Operational attributes:.attr(同上)
  • Hide: .hide (1000) parameter milliseconds
  • Show: Show (1000)
  • JS page loads been performed: the window.onload = function () {}
  • JQ page loads been performed: $ (Document) .ready (function () {})

Equivalent to $(function( ){ })

  • Composite click event: Toggle (fun1, fun2, fun3)
  • Composite mouse motion events: hover (fun1, fun2)
  • Completely removed, including its own label: .remove ()
  • Leaving the label, delete text: .empty ()
  • Selected elements add one or more event handlers: .bind (Event, Data, function)
  • Additional data element is selected, or retrieve data from the selected elements: .data (name, value)

Custom plug-ins

http://caibaojian.com/jquery-extend-and-jquery-fn-extend.html

jQuery为开发插件提拱了两个方法They are:

  • jQuery.extend(); $.extend()

JQuery add class to class methods, static methods can be understood as add

  • jQuery.fn.extend(); $.fn.extend()
    jQuery.fn = jQuery.prototype

JQuery.prototype get in on the extension is to add "member function" for the jQuery class

  • to sum up:

JQuery.extend call () method will not extend to the instance of the object, the method needs to reference it also achieved by jQuery hydrocarbons, such as jQuery.init (), and jQuery.fn.extend () method is called the extended to the prototype object, it instantiates a jQuery object, when it has these methods,

Published 32 original articles · won praise 1 · views 1159

Guess you like

Origin blog.csdn.net/ASYMUXUE/article/details/105158740