Into the pit-up posture

Source: Internet
Author: User

First, preface

So far also has been pulled a few small projects, to be counted as a bit of experience, the following summarizes some of the pits encountered, and up to the posture, will they record down, hope that the future do not hang to their own.

The following summary is to have a pot of stewed pro-test pits, the next time you open a project to see a look, hope that the final rework.

Second, the textFirst Pit: A binding event in jquery Remember to write the $ (function () {}) inside

To explain, originally I did not know why the binding event to write to $ (function () {}), and then really silly very naïve to put $ ("xxx"). Click (function () {}), and throw it all out of $ (function () {}). If it doesn't seem like much of a problem in a normal HTML page, the problem arises when the page is partially using the Load method in jquery: Load (Url,[data],[callback])

1 <!DOCTYPE HTML>2 <HTML>3 <Head>4     <MetaCharSet= "UTF-8">5     <title>This is the first page of a.html</title>6 </Head>7 <Body>8     <ButtonID= "Change">Load b.html</Button>9     <DivID= "Changeme"></Div>Ten </Body> One <Script> A $(function(){ -     $("#change"). Click (function(){ -         $("#changeme"). Load ("b.html",function(){ the             //Do sth -         }); -     }); - }); + </Script> - </HTML> +  A  at  - <Div> - <!--This is page two, b.html. - - <ButtonID= "ClickMe">Please point me</Button> - <Script> - //Here's the point . in $("#clickme"). Click (function(){ - Alert (1) to }); + </Script> - </Div>
View Code


Like the above, if #clickme's binding does not write in $ (function () {}) The result is if the a.html inside the # Changeme load the b.html and then load the other things and then load back to the b.html, this time b.html was loaded 2 times, then bound 2 times the Click event, then will be happy to play 2 alert to you, more fun is loaded several times to play

In summary, write the event bindings in the $ (function () {})

Second not the pit: JavaScript and CSS version issues

As a wild front-end code dog, have you ever been asked by your project leader "eh?" We need to do a what, anyway, there is no art, you will follow what the page to pick the same bar ", this is seriously not attached to the situation you can endure? Usually give less money still old let you work overtime also forget, as an upright front, net take you when unauthorized people, do a project even the art are not to match this kind of thing you can endure? I can't bear it anyway. So I have been a few pages, and then I found some JS and CSS look big slightly high ah, style.css?v=1.0.526 what ghost Ah, crouching trough, originally thought they css Durt dynamic generation of good felling, so chrysanthemum a tight ah have wood, For fear of the little man what to play to throw other pages can not run Wow, the hair crashed out wow ...

Then the hard work of overtime dog ushered in the project is not tight, the spring has a job, there is still time to go up on the internet up posture has to wow, although continue to wild, but it seems to have found the broken sweater on the missing thread has a wood has wow

The point is, you don't make a coincidence today, see the following description

"We all know that JavaScript and CSS are static files, if the address is not changed, the browser will cache these files, it means that when we need to change JavaScript or CSS files, even if we change the backend, then the client is not visible, this in the" JS eminence " ERA is unacceptable because almost all Web applications now rely heavily on JavaScript, and all Web sites need to use CSS. In the projects I've been through, even many years of experience with programmers have appeared in JavaScript and CSS file version problems, such as customer let fix a bug, this bug is caused by JavaScript, the programmer fixed, or the customer said to change a background color, However, when we give the customer deployment or code to customer deployment, the customer said that the bug still exists, this time the programmer often said the words will appear "I am local is good ah", finally find someone to help, found that the original is not clear browser cache, so some programmers hurriedly to the customer said: " You need to ctrl+f5 clear the browser's cache. " Every time I hear that, it's like turning off the lights and leaving me a room black, first of all, how many ordinary users will use CTRL+F5? Second, how many users are willing to go to ctrl+f5? So what? I think a lot of programmers know to add a version number, so that the browser will be considered a new file, such as the original is http://www.a.com/app.js you now only need to change the address to http://www.a.com/app.js?v=1.0 But if this action is manual, then 10 times basically at least 5 times the programmer will forget, then that's why we need front-end build "

Citation and attribution: http://www.cnblogs.com/cnblogsfans/p/5093012.html

(although this sentence other than the other did not understand, but) finally the truth of the wood has ah, my previous hair off is how wronged ah, unexpectedly all special do not know the internet Baidu what it is, but in any case later when the family page when the minister will not be afraid of the heart of the mind, a page over the past five pages ah. Home travel kill people kill must force lattice, take away or in this outfit AH ~ (although the ash often pits is now only manual modification, installed after the Beep ran, but good stimulation has wood there ah).

Iii. Summary

This time to the pit of the finishing first so much, next time think of something else to say.

In-pit posture

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.