Is there any problem with writing the with format like this in JavaScript? Why not?

Source: Internet
Author: User
Result of normal running: {code...} cannot run after using with: {code...} where is the problem! {Code:

aobj.href="abcdefghi";aobj.target="_blank";aobj.style.backgroundColor='yellow';aobj.style.float= "left"; aobj.style.overflow="hidden";aobj.appendChild(img);

Results that cannot be run:

wiht(aobj){href="abcdefghi";target="_blank";style.backgroundColor='yellow';style.float= "left"; style.overflow="hidden";appendChild(img);}

Please advise if you have any questions!

I changed it for me. Thank you!

Reply content:

Result of normal operation:

aobj.href="abcdefghi";aobj.target="_blank";aobj.style.backgroundColor='yellow';aobj.style.float= "left"; aobj.style.overflow="hidden";aobj.appendChild(img);

Results that cannot be run:

wiht(aobj){href="abcdefghi";target="_blank";style.backgroundColor='yellow';style.float= "left"; style.overflow="hidden";appendChild(img);}

Please advise if you have any questions!

I changed it for me. Thank you!

Wiht spelling error

aobj = {    href: null,    target: null,    style: {},    appendChild: null};with(aobj) {    href="abcdefghi";    target="_blank";    style.backgroundColor='yellow';    style.float= "left";     style.overflow="hidden";    appendChild(img);}

With cannot use undefined attributes

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.