IE conditional comment gotcha
<!-- [if IE]> (bad)
<!--[if IE]> (good)
<!-- [if IE]> (bad)
<!--[if IE]> (good)
function loadScript(url, callback){
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState){ //IE
script.onreadystatechange = function(){
if (script.readyState == "loaded" ||
script.readyState == "complete"){
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function(){
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
One of the great CSS tips I got from Zen of CSS was to put an id on the body tag of your html pages. This makes it really easy to use one CSS file for your entire site (a optimization trick) and allow you to target elements on specific page easily without creating a lot of unnecessary content wrappers or bogey class names.
It is also very simple thing to do on MVC sites. Using the convention of Controller+Action give an easy identifier (if you’re using areas or something else you will need to tweak this a little).
1. 替 body 加上 id,就可以全站共用一組 CSS 檔案。
2. Web Application 可以用 controllwe + action 作為 body 的 id。
For example, you can separate the piece that knows about DOM elements …$(function() { $("#getTweets").click(function() { $(document).trigger("fetchTweets", [$("#tweets"), $("#screenname").val()]); return false; }); });… from the piece that knows about Twitter, and include the pieces independently …$(document).bind("fetchTweets", function(e, element, screenname) { $(element).getTwitter({ userName: screenname, numTweets: 10, loaderText: "Loading tweets...", slideIn: true, showHeading: true, headingText: "Latest Tweets", showProfileLink: true }); });
用 $(document).bind 跟 $(document).trigger 來降低程式碼之間的相依性。