JavaScript notes (Everything)

Source: Internet
Author: User

Two-dimensional code scaling is the most standard in multiples of 43PX.

NuGet Related Management http://www.cnblogs.com/dudu/archive/2011/07/15/nuget.html

Study Note: http://kb.cnblogs.com/page/143190/

Dynamically create tags, add styles to tags, class, and so on vardtproductname=$ ("<dt></dt>", {style: "Text-overflow:ellipsis;o Verflow:hidden;white-space:nowrap; "});

CSS style Selector

Definition and usage

: The last-child selector matches each element that belongs to the last child element of its parent element.

tip:P:last-child is equivalent to P:nth-last-child (1).

In JavaScript, you can use the ChildNodes property to return an array that contains the entire child nodes of a given element node, as shown in the code:

01

<body>

02

<ulid="action">

03

    <lititle="第一段文字">第一个</li>

04

    <lititle="第二段文字">第二个</li>

05

</ul>

06

<scripttype="text/javascript">

07

var attr_p = document.getElementById("action");

08

alert(attr_p.childNodes[1].childNodes[0].nodeValue);

09

</script>

10

</body>

If you want to get the text node within the first Li of the UL with ID action (such as Get: first), you can use ... childnodes[1].childnodes[0].nodevalue this method to find, use ... childnodes[1]. Firstchild.nodevalue can also find the first Li text node,
Conclusion Childnodes[0] is equivalent to FirstChild, and whenever and wherever it is important to access the first element of the childnodes[] array, we can write it firstchild,dom also provide a corresponding LastChild attribute.
It is important to note that the space node problem of the FF can be determined by using the NodeType attribute on the node type until the element node is found

Call through JavaScript

After adding it in the CSS position:relative; , start the scrolling listening plugin via JavaScript code:

Copy

$ (' body '). Scrollspy ({  target:  ' #navbar-example '  })
Method .scrollspy(‘refresh‘)

When you add or remove elements from the DOM while using the scroll listener plug-in, you need to call this refresh method as follows:

Copy

$ (' [data-spy= ' scroll "]). each (function  ()  {  var  $spy  =  $ (this). Scrollspy (' Refresh ') })
Parameters

Parameters can be passed through the Data property or JavaScript. For the Data property, its name is the attachment of the parameter name to a data- later composition, for example data-offset="" .

Name

Type

Default value

Describe

Offset

Number

10

The offset (number of pixels) relative to the top when the scroll position is computed.

Event

Event Type

Describe

Activate.bs.scrollspy

This event is triggered by a rolling listener plug-in whenever a new entry is activated.

$ (' #myScrollspy '). On (' Activate.bs.scrollspy ',  function  ()  {  //do something ...  })

NuGet installs the specified version of the package tutorial

1,nuget program Commands

Http://docs.nuget.org/consume/package-manager-console-powershell-reference

2 Tutorials

Use NuGet to install a specific version of the package or update it to a specific version

Recently pondering MVC and entityframework, the use of VS is version 2013, in the NuGet GUI interface installed EntityFramework (the default installation of the latest version, how to install the specified version has not been found), MVC4 does not support Entityframwok 6, as the MVC sample project Musicstore steps through.

Try to update the MVC version of the various failures, only try to reduce the entityframework version. However, the GUI interface of NuGet cannot be installed or updated to the specified version of Entityframwok. Search the Internet on the relevant information (in fact, it is easy to search), do a memo.

First open the Package Manager console: Tool →nuget Package Manager → Package Manager console

Open the command line interface as shown

Install the specified version of the package (for example: EntityFramework 5.0):

Pm> install-package entityframework-projectname musicstore-version 5.0

Update to the specified version of the package (for example, Entityframewrok 6.0):

Pm> update-package entityframework-projectname musicstore-version 6.0
Update-package Command Related parameter description:

Parameter

Type

Description

-id

String

Specifies the Id of the package to be updated.

-projectname

String

Specifies the name of the project in which packages should is updated.

-version

semanticversion*

Specifies the new target version of the package as a result of the update.

-source

String

Specifies where to look for package updates, overriding the package sources that is specified in the Options dialog. This value can is either a URL to a remote repository or a path to a local repository or the name of a package source spec Ified in the Options dialog.

-ignoredependencies

Switch parameter

If set, NuGet would ignore dependency packages and only update the main package.

-safe

Switch parameter

If set, NuGet would only update to a new version of the same major and minor versions as the previous package. For example, if the old version is 1.2.0, NuGet would accept the update package with version of 1.2.1 or 1.2.9999 but it WI ll not accept 1.3.0.

-includeprerelease

Switch parameter

If set, NuGet would consider prerelease packages as candidates for updates.

-reinstall

Switch parameter

If set, instead of updating the package to the latest version, NuGet would uninstall the package and reinstall the same ver Sion. This was useful when, for example, you ' ve updated the target framework of your project, e.g. NET 4.0 to. NET 4.5, and You want to reference. NET 4.5-specific assemblies in the package. You can ' t set this parameter together with the-version parameter.

Reference: Http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference

Basic syntax if (data) {...}

The!data state is empty or undefined or false will perform the following method

Data will not proceed to the following method:

Storage Events

Storage also provides the storage event , which can trigger the storage event when the key value is changed or clear, as the following code adds a listener that changes the storage event:

if (Window.addeventlistener) {Window.addeventlistener ("storage", Handle_storage,false);} Else if function if (!e)       {e=window.event;}  }

The specific properties of the storage event object are the following table:

Property

Type

Description

Key

String

The named key is added, removed, or moddified

OldValue

Any

The previous value (now overwritten), or null if a new item is added

NewValue

Any

The new value, or null if an item is added

Url/uri

String

The page that called the method, the triggered this change

Blog Park , Uncle Tom . [Eval () usage Reference ]

Using the new function () construct is similar to eval () and should be approached with care. This may be a powerful construct, but is often misused. If you absolutely must use eval (), you might consider using the new Function () instead. There is a small potential benefit because the code evaluation in the new function () is run in the scope of the local function, so any variables that are evaluated in the code that are defined by VAR will not automatically become global variables. Another way to prevent an automatic global variable is to encapsulate the eval () call into an immediate function.

Consider the following example, where un namespaces are polluted only as global variables.

Console.log (typeof un); "Undefined"
Console.log (typeof deux); "Undefined"
Console.log (typeof trois); "Undefined"

var jsstring = "var un = 1; Console.log (un); ";
eval (jsstring); Logs "1"

jsstring = "var deux = 2; Console.log (deux); ";
New Function (jsstring) (); Logs "2"

jsstring = "var trois = 3; Console.log (trois); ";
(function () {
eval (jsstring);
}()); Logs "3"

Console.log (typeof un); Number
Console.log (typeof deux); "Undefined"
Console.log (typeof trois); "Undefined"

The other eval () differs from the function construct in that eval () interferes with the scope chain, and function () is more scrupulous. No matter where you perform function (), it only sees the global scope. So it can be very good to avoid local variable pollution. In the following example, eval () can access and modify variables in its outer scope, which is not function (note that using function and new function are the same).

(function () {
var local = 1;
Eval ("local = 3; Console.log (local) "); Logs "3"
Console.log (local); Logs "3"
}());

(function () {
var local = 1;
Function ("Console.log (typeof local);") (); Logs undefined
}());

As you can imagine, when using Eval to execute JSON, the JSON string is usually enclosed in parentheses: eval (' (' + JSON + ') '), because of the grouping operator, which is the pair of parentheses, Causes the parser to force the JSON curly braces to be parsed into expressions rather than blocks of code.

try {
{"X": 5}; "{" and "}" are parsed into blocks of code
} catch (Err) {
SyntaxError
}

({"X": 5}); The grouping operator forces the "{" and "}" to be parsed as object literals

It is also important to note that function declarations are useful in conditional statements, but are not standardized, meaning that different environments may have different execution results, so it is best to use function expressions:

Don't do this!
Because some browsers return the function of first, and some browsers return the second

if (true) {
function foo () {
return ' first ';
}
}
else {
function foo () {
return ' second ';
}
}
Foo ();

Instead, in this case, we're going to use a function expression
var foo;
if (true) {
foo = function () {
return ' first ';
};
}
else {
foo = function () {
return ' second ';
};
}
Foo ();

We know that this anonymous function calls the returned function (the function with the identifier g) and assigns the value to the outer F. We also know that a named function expression results in an extra function object that is not the same as the returned function object. So the extra G-function died in the closure of the return function, so the memory problem came up. This is because the functions inside the IF statement are declared in the same scope as G. In this case, unless we explicitly break the reference to the G function, it always occupies memory.

var f = (function () {
var f, G;
if (true) {
f = function g () {};
}
else {
f = function g () {};
}
Set G to null and it won't take up any more memory.
g = null;
return F;
})();

JavaScript notes (Everything)

Related Article

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.