Notable points in JavaScript (1)

Source: Internet
Author: User

    1. The difference between an array and an object in a Delete operation

Delete operations are performed on an array, and the effect differs from the delete operation on the object;

  1. Delete operations differ between objects and arrays
  2. Delete the properties of an object first
  3. var originobj={name: ' Spark ', inner:{top: ' Shirt ',short: ' T-string '};
  4. Delete Originobj.inner;
  5. for (var prop in originobj) {
  6. ? document.write (prop);
  7. }
  8. Name
  9. Delete the index of an array
  10. array=[1,2,3];
  11. delete array[1];
  12. document.write (array);
  13. 1,,3

?

    1. Note Points for the setinterval ()/settimeout () function

For the SetInterval () and SetTimeout () functions, you need to be aware of the first parameter--the JS code in the form of a string, whose scope is global! It is therefore invalid to use the method as follows!

    1. function imgslide () {
    2. ?? pic=document. getElementById (' slide '); window. setinterval (' Pic.src=change () ', 1000);
    3. }

In function Imgslide (), SetInterval () invokes the PIC variable, but if the variable is declared in the function setinterval () cannot be called successfully because the first parameter of the SetInterval () code is scoped to the global/outermost layer, i.e. If a variable is used in code, the variable must be a global variable, regardless of where the setinterval () method is called.

    1. How to use JS to manipulate CSS classes for DOM objects
      1. When adding classes and removing classes to HTML tags on existing classes with JS, you can use the Split method only to remove the first element (the label's original class name) and add and remove it!
        1. Element.classname=element.classname.split ("") [0]+ " wrong";

Notable points in JavaScript (1)

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.