JavaScript Knowledge Point Small note

Source: Internet
Author: User

// Customizing a new property // ' <li data-id= ' + val.id + ' > ' + datas[i].name + ' </li> ' var channel_id = $ (this). Data (' ID '); // gets the value of the property

// intercept values in the current page link var // params:?id,date       var id = params.substring (40);

The classification of basic functions in JS

Normal function func (ARG) {   return true;} anonymous function var func=function (ARG) {       return true;   } Self-executing function, which defines a function to execute itself F1 (ARG) {  alert (arg);  } F1 (' 123 ')//The self-executing function above can also be written; (function (ARG) {alert (arg);}) (' 123 ')

Non-null judgment

Native  
HTML: <div class= "Submit" onclick= "Submitinfo" > Submit </div> <script> function Submitinfo () { var info=document.getelementsbyclassname (' Submit '). Value; if (info) {///(!!) ) return false; } else{ return true; } }

Jquery
<script>
   $ (. Submit). Click (function () {
var info = $ (. Submit). val ();
if (info = = "") {///(!!!) )
return false;
}else{
return true;
}
}
</script>

Determine the method to be executed based on CSS styles

$ (". Find_nav_list"). Find (' Li '). Click (function(){    var$ This= $( This);//cache the currently clicked Li Object        varTHISCSS = $ This. Hasclass ("Find_nav_cur");//gets whether the current object contains the class style of execution (!!! )    if(THISCSS) {//If the current object has a class style (which can be understood as currently selected)$ This. Removeclass ("Find_nav_cur"); }Else{        $ This. siblings (). Removeclass (' Find_nav_cur '); $ This. addclass ("Find_nav_cur"); }

Determine if there is a style
$ ("#id"). Hasclass ("ClassName")? Console.log ("Have this class."): Console.log ("Does not have this class.");

Switch Class class
Jquery.toggleclass ()//check each element for the specified class, if none is added, some words are deleted

How to tell if there is a CSS property value in the tag

Write CSS into inline style <a style= "float:left;" > </a>, so you can get the value of the style and then determine if there is margin;$ (". Acont a"). each (function () {  var ofright = $ (this). attr ("style"). IndexOf ("margin"); (!!!  if (ofright! = ( -1)) {alert ("defined");}  else{$ (this). css ({"float": "Left", "Font-size": "12px", "margin": "10px"});});

  

window.location Detailed

// Properties:hash            // URL (anchor) starting from pound sign (#)host            // hostname and port number of current URL hostname        // hostname of the current URL href            // full URLpathname        // The path of the current URL part port            // port number of the current URL Protocol        / /url of the current URL         (Query section) from the question mark (?)
Jump to the specified page
window.location.href= ' denglu.html ';
Window.location.reload (' 11.html ')
Back to previous page
<a href= "Javascript:history.go ()" ></a>
<a href= "Javascript:history.back ()" ></a>
  The difference between the two:
   History.go (-1): Return to the previous page, the contents of the original page form will be lost. Back () and vice versa, the contents of the original page form are retained.
JS Refresh page
Location.reload ();
Reload page, local refresh
<a href= "Javascript:location.reload ()" > Reload page, local refresh </a>

Summary http://www.jb51.net/article/32749.htm
Http://www.qdfuns.com/notes/18224/ce8d9da1f4565cbbaaf694a97b70d2d5.html

JS's function binding event

 bind bind event
function (e) { $ ("#fileImage"). Click (); }); // A bound click event

enter key to add login function

onkeydown= "Keylogin ();" >  //(!!) )    function  keylogin () {        if(event.keycode = =)   //  (!!! )13 Default enter key              $ ('. Submit '). Click ();        }} </body>        

JS function does not respond to several reasons

1, JS related files are not introduced. 2, JS file up and down order there is a problem.

Debugging JS Specific steps

1. View the values of variables in the program. 2, positioning error.

String Stitching problem

1, escape character \ "The colon after the best and the outer curly brace of the single double colon inconsistent."

Clear form Contents

$ (". Bs_it"). attr (' value ', ');

Judging by whether or not there is content in the element

if ($ (". My_collect"). HTML ()! = "") { //(!! )    $ ('. collect_msg '). Hide ();}

JS attribute operation

The HTML code is as follows <a class= "main" href= "#" ></a>var a = Document.getelementbyclassname (' main ' ); A.href//(!!) ) Property Operation

return Details:

If or for after return bounce method  

Simulating if -judging events

. html (<div class= "fl li02" > ' + (type = = 1?) "Public": "specified") + ' </div>);

A function that iterates or writes the same event, if the event overlaps or the subsequent event is overwritten, one of the solutions: give them different class names or ID identifiers.

How the page refreshes in

<body class= "Body" onload= "Openwin ()" > Function Openwin () {Alert (' network error, please try again! ‘) }

The implementation of the following methods can only be implemented after agreeing to the terms

if ($ (". Input_check"). Is (": Checked")) {    //(!! ) Selected        $.fn.request (url,data,function (data) {            if (data.success = = = True) {                alert (' registered successfully '); location.href = ' Denglu.html ';            } else{                alert (data.msg);}}        );    else{    alert ("You have not agreed to the terms");    }

The value of JS parameter transfer

function Ordersub (OID) {var ordid = oid; ) Declaration and then use}ordersub (info.id);

Image click to zoom Out

<style>.max{width:100%;height:auto;}. Min{width:100px;height:auto;} </style><script>$ (function () {    $ (' #img '). Click (function () {        $ (this). Toggleclass (' min ');        $ (this). Toggleclass (' Max ');    }); </SCRIPT><HTML>

JS Replace content

jquery topics

// get Dom instead of native var  Sidebar = $ ('. #sidebar ')        = $ ('. Mask ')

Manipulating CSS Properties!!! This previous study in every time to forget,, ah

Manipulating individual CSS Properties
CSS ("propertyname", "value");//Note to add a colon!!!
JQ.CSS ("Color", "#000")

Manipulating multiple CSS Properties is the JSON format
CSS ({"PropertyName": "Value", "PropertyName": "Value",...}); /Pay attention to the colon!!!
Jq.css ({"Color": "#000", "font-size": "10px"})//json format each small content is separated by commas, then the key value is enclosed in quotation marks, and the outside is given a {} curly brace.

Action Property attr (), usage with CSS ()

Animate () method
$ (' html,body '). Animate ({scrolltop:0},600)//understanding: Key-value pairs, the key is to perform the action, the value is the time or distance, the following key is different, of course, the back of the 600 is not required.



Using typeof to return variable types

document.write (typeof  temp)var temp = +; // Output Number

Intercept string

// Example var // params:?id,date       var id = params.substring (42);

   

function (name) {        varnew RegExp ("(^|&) + name +" = ([^&]*) (&|$) ");         var r = window.location.search.substr (1). Match (reg);         if (r!=nullreturnreturnnull;    } var id = $.geturlparam (' id '); // The value of the ID in the Intercept link

Review JS Basic knowledge

Document.style.color= "#cccccc";d ocument.innerhtml= "Hello World"; function MyFunction (A, a) {return A *b;} document.getElementById ("Demo"). Innerhtml=myfunction (4,3); //  A

JavaScript Knowledge Point Small note

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.