作者归档:船长

Learning JavaScript 2

with "Visual QuickStart Guide javascript and Ajax for the Web, Sixth Edition"

Chapter 2. Start Me Up!
Scripts can be put in one of two places on an HTML page: between the <head> and </head> tags (called a header script), or between the <body> and </body> tags (a body script).
        <script language="javascript" type="text/javascript">
          document.write("Hello, world!");
       </script>

internal scripts

external script, a separate file that just contains javascript.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
     <title>My second script</title>
     <script language="javascript" type="text/javascript" src="script02.js">
     </script>
</head>
<body bgcolor="#FFFFFF">
     <h1 id="helloMessage">
     </h1>
</body>
</html>

script02.js:
window.onload = writeMessage;
// Do this when page finishes loading
/*
a function shown with parentheses means that the function is being called, right then and there. When it's without parentheses, (as it is here) we're assigning it to the event handler, to be run later when that event happens.
*/
function writeMessage() {
     document.getElementById("helloMessage"). innerHTML = "Hello, world!";
}

<noscript>
<noscript>
     <h2>This page requires javascript.</h2>
</noscript>

On non-javascript browsers, a message appears saying that this page requires javascript.

confirm() & alert()
if (confirm("Are you sure you want to do that?")) {
     alert("You said yes");
}
else {
     alert("You said no");
}

condition
(condition) ? truePart : falsePart;
like:
myNewVariable = (condition) ?
truevalue : falsevalue;
or
if (condition) {
        truePart;
}
else {
        falsePart;
}

prompt()
var ans = prompt("Are you sure you want to do that?","");
if (ans) {
     alert("You said " + ans);
}
else {
     alert("You refused to answer");
}
 If a variable is created inside a function, other functions don't have access to it, as it's local to that function. If it's created outside any function, it's global, and everything has access to it.

redirect
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
     <title>Welcome to our site</title>
     <script src="script07.js" type="text/javascript" language="javascript">
     </script>
</head>
<body bgcolor="#FFFFFF">
     <h2 align="center">
         <a href="htmlpage.html" id="redirect"> Welcome to our site… c'mon in!</a>
     </h2>
</body>
</html>

window.onload = initAll;
function initAll() {
     document.getElementById("redirect"). onclick = initRedirect;
}
function initRedirect() {
     window.location = "jspage.html";
     return false; //The return false says to stop processing the user's click, so the href page doesn't get loaded.
}
On first glance, we might think that we could just set the onclick handler globallythat is, as the page is loadingbut we can't. There's a chance, particularly for a large and complex page, that the browser will not yet have come across that redirect id, and if that happens, javascript won't be able to assign the onclick handler. Instead, we have to wait until the page has completed loading, and that's done via onload.

action after the user clicks a link
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
      <title>Welcome to our site</title>
      <script src="script08.js" type="text/javascript" language="javascript">
      </script>
</head>
<body bgcolor="#FFFFFF">
      <h2 align="center">
        Hey, check out <a href="
http://www.pixel.mu/" id="redirect">my cat's Web site</a>.
      </h2>
</body>
</html>

window.onload = initAll;

function initAll() {
     document.getElementById("redirect"). onclick = initRedirect;
}

function initRedirect() {
     alert("We are not responsible for the content of pages outside our site");
     window.location = this; //THIS!!!
  /*The javascript keyword this allows the script to pass a value to a function, solely based on the context where the keyword is used.*/
     return false;
}

document.referrer
A referrer page is the page that the user was viewing before the current page, or, in other words, the page the user came from.
function writeMessage() {
     if (document.referrer != "") {
         document.getElementById("referrerMsg"). innerHTML = "I hope you like this page
better than " + document.referrer;
     }
}

Unobtrusive scripting: An approach to scripting Web pages using javascript, in which the behavior of the Web page is kept separate from its content, that is, the HTML is in one file, and the javascript is in another. Additionally, the term "unobtrusive scripting" is used when code is written such that visitors without javascript (or with less-capable browsers) get all the functionality of a site, just with a less-rich user experience.

And finally, this being the real world, we also know that sometimes the simplest way to hammer in a nail is to grab a rock and pound the nail into the wall. This, for instance, is why we used innerHTML back in Script 2.3, even though it's not part of the W3C DOM.

发表在 站长文档 | 留下评论

Learning Javascript

with "Visual QuickStart Guide javascript and Ajax for the Web, Sixth Edition"
By Tom Negrino, Dori Smith
target browsers:
Internet Explorer 6 or later; Firefox 1.0 or later; Netscape 7 or later; all versions of Safari; and Opera 7 or later.

Chapter 1. Getting Acquainted with javascript

What javascript Is
Despite the name, javascript and Java have almost nothing to do with one another.

With Java, a descendant of the C and C++ programming languages, programmers can create entire applications and control consumer electronic devices.
Microsoft dropped Sun's Java from Windows altogether, after creating its own Java-like language, C#.
If javascript isn't related to Java, then why do they have such similar names? It's another example of one of the computer industry's most annoying traits: the triumph of marketing over substance.
and ever since then, writers like us have made good money explaining that javascript and Java are very different things.
This Microsoft version of javascript is called JScript.

What javascript Can Do
 A rollover is an image that changes when you move the mouse pointer over it.
javascript has some limitations built-in, mostly for security reasons:
 1.javascript does not allow the reading or writing of files on client machines. The only exception is that javascript can write to the browser's cookie file.
 2.javascript does not allow the writing of files on server machines.
 3.javascript cannot close a window that it hasn't opened.
 4.javascript cannot read information from an opened Web page that came from another server.

What Is Ajax?
Ajax is shorthand for Asynchronous javascript and XML.
In the larger scheme of things, what's generally referred to as Ajax is the combination of these technologies:
 XHTML
 CSS (Cascading Style Sheets)
 The DOM (Document Object Model) accessed using javascript
 XML, the format of the data being transferred between the server and the client
 XMLHttpRequest to retrieve data from the server

javascript is an object-oriented language
Objects
Properties, Objects have properties.
Methods, The things that objects can do are called methods.
dot syntax
 document.images.name
 forms.elements.radio.click()

The representation of the objects within the document is called the Document Object Model (DOM).
Each of the objects on the tree is also called a node of the tree. If the node contains an HTML tag, it's referred to as an element node. Otherwise, it's referred to as a text node.
Events are actions that the user performs while visiting your page. javascript deals with events using commands called event handlers.
The 12 most common javascript event handlers :
 onabort
 onblur
 onchange
 onclick
 onerror
 onfocus
 onload
 onmouseover
 onmouseout
 onselect
 onsubmit
 onunload

value Types:
 Number
 String
 Boolean
 Null
 Object
 Function
value returned by a function
Variable names cannot contain spaces or other punctuation, or start with a digit. They also can't be one of the javascript reserved words.  javascript is case sensitive.
Operators:
 x + y (Numeric)
 x + y (String)
 x – y
 x * y
 x / y

 x % y Modulus of x and y (i.e., the remainder when x is divided by y)
 x++, ++ x
 (if x is 5, y=x++ results in y set to 5 and x set to 6, while y=++x results in both x and y set to 6. The operator – (minus sign) works similarly.)
 x–, –x
 -x

Assignments:
 x = y
 x += y

  Same as x = x + y
 x -= y
 x *= y
 x /= y
 x %= y

Comparisons:
 x == y
 x != y
 x > y

 If you are comparing strings, be aware that "a" is greater than "A" and that "abracadabra" is less than "be".
 x > = y
 x < y
 x <= y
 x && y
 x || y
 !x

Writing javascript-Friendly HTML
Structure, presentation, and behavior
When split up this way, your sites will contain three types of text files:
 XHTML: content and structure
 CSS: appearance and presentation
 javascript: behavior
CSS:
A <div> is a block-level element, that is, there's a physical break between it and the elements above and below it. A <span> isn't block-level; instead, it's inline, so you can apply it to, for instance, a single phrase within a sentence.
A class identifies an element that you may want to use more than once. An id identifies an element that is unique to that document.

发表在 站长文档 | 留下评论

一个都不能少 1999

一个都不能少 1999

http://www.imdb.com/title/tt0209189/

感觉太平淡了。 这也是这部电影的特色。 电影情节平淡如水。 没有电脑特效, 没有动作特技;再加上没有一个专业演员, 电影的画面平淡如水。说是电影,但更像是偷拍下来的记录片。
唯一让我不平的是那慢慢发现的平淡中夹着的些许让人感动的执着。
7

发表在 电影评论 | 留下评论

那天我经过关公庙

听到上面这个故事, 我想起一件类似的事来。
那事发生得有一段时间了。。。屈指一算,也有二十来年了。 
当年我们华山和嵩山一起去攻打金刀门, 不想中了金刀门的埋伏,被杀得死伤无数。乱战中我正想找个清静点的地方躲藏, 撞进了金刀门后院的一间小屋,不想发现掌门夫人和慧明方丈也呆在那里。方丈躺在屋角的草堆上,掌门夫人正哭泣着在给他包扎大腿上的伤口。我正想回避出去,可没想到不由我分说,掌门夫人过来一把抓住我的衣领,要我拿着一只玉手镯回华山叫她女儿带着凤凰笛子过来。
我没弄懂怎么回事, 就被刘掌门夫人扔出了后院高墙。我很高兴,因为院子里面刀光剑影,实在太乱了,而我是个喜欢清静的人。在里面时一直想出去,可惜那墙我爬不上去。
现在好了,现在可以回华山了。来时我正在读着诗集烤白薯,匆忙间被召集去攻打金刀门,而现在正好顺道回去看看白薯烤焦了没有了。
而且是一个人。太好了。来时一大帮,吵得很。一边走,掌门还让我们一边唱华山之歌,”华山,华山,好大的华山。。。“。那歌词没有诗意不要紧,而且不压韵,我一听就发晕,而且还要我唱得比嵩山弟子的“少林颂”大声,恶心死我了。现在好了。这二百多里路我可以一个人走了。
当时正是5月,山花烂漫。我想写诗。”五月花开一大山“,可就是一直想不出下句。也许是因为最近没有爱情的原因。
我是在经过清风寨时才发现自己迷了路的。
当时我进寨子路边的一酒店吃饭。我依旧点了三个包子。结账时小二要了我10文。我跟小二说理,他说这里的包子一直是10文三个,不是9文, 而且他说他们的店名一直是“丰裕酒店”,没有叫过“德康饭庄”。在找了半天,没有找到我那日题有“老鼠爱大米”字样的饭桌后我终于相信了他的话。也就是说华山在北面,而我向南跑了一天。
但事后证明我走的方向总体来说应该是对的。
也就因这些机缘巧合,第二天中午我才经过了陆家沟附近的那个关公庙,才看到那件我一生也不会忘记事情

正文待续。。。

发表在 盖世武功 | 一条评论

天下第一剑 1968

天下第一剑 1968

http://www.imdb.com/title/tt0062959/

故事发生的南北剑都还在的时候。 当时有个小姐妆化得很有特色。

最后的决战很无奈, 当时程小东,徐克都还没上场。 画面很单调, 两位高手竟然都靠瞪眼睛拖时间, 后面又加入了慢动作敷衍。 我很着急, 怕他们互相抓起头发来。但这事终没有发生, 于是画面始终都是单调的。

4

发表在 电影评论, 盖世武功 | 留下评论

马背上的法庭

马背上的法庭

看这部片我更多的是想回味一下云南那连绵不断的大山。
没想到在里面还看到多少少数民族的生活。

6

发表在 电影评论 | 留下评论

美丽的大脚 2002

美丽的大脚 2002

http://www.imdb.com/title/tt0361634/

女主角的献身教育镜头不是很多, 更多的是她的偷情事迹, 不明白这有什么让女配角歇斯底里地感动流泪的。
影片做作的场面太多了, 让人看了反感。

5

发表在 电影评论 | 留下评论

暖春 2004

暖春 2004

《暖春》是一部很缺心眼的电影。它专攻人的弱点,完全不留任何情面,招招致命,并且一剑刚过一掌又出,完全不给人喘气机会。
我怀疑这个没有半点大侠风范的导演乌兰塔娜是专攻眼科医学的。而和山西电影制片厂一起参加了《暖春》拍摄工作的另一个位单,XX贸易公司实际上很有可能是一家纸巾代理商。
是的,虽然知道他们是预谋好的,但观看影片你还是不得不准备一卷足本的纸巾。为防止体液流失过多而导致休克,请注意及时补充身体水分。

8

发表在 电影评论 | 留下评论

鹰爪铁布衫 1977

鹰爪铁布衫 1977

http://www.imdb.com/title/tt0076939/

7

前段时间看了《独臂刀》 后想看儿时看过的经典武打电影《鹰爪铁布衫》。 想了好多天, 今天终于看了。

《鹰爪铁布衫》 的确是一部很不错的武侠电影。 电影开头的武功说明和电影后段的穴位介绍图在今天看来很有特色。 电影的故事也不错, 虽然世界小了点。

和今天的电影相比, 当时的打斗并不落后。 演员大多是练过的, 一招一招都显刚劲有神。 不像现在的电影, 周杰伦一旦须要也能成为武林高手。

以前管这个电影叫武打电影, 今天发觉应该是武侠电影。 里面有两个大侠, 和一少侠,小女侠。我突然发现比起当年, 现在的武侠电影少得可怜。 最近几年拍的好像只有《卧虎藏龙》算得上是一部武侠电影。 像
《英雄》没有什么江湖可言, 侠也不是体现的重点, 到了〈满城尽带黄金甲 〉里面干脆没有一个侠了,更谈不上江湖了。

虽然《鹰爪铁布衫》是部不错的电影,但我发现我看错了。 这部别名可以叫《两个鸡蛋》的电影并不是我多天来想看的那部。 我记错了。 或《鹰爪铁布衫》从小我没有没有完整看完过。 而我真正想看的电影应该是《无敌鸳鸯腿》。。。

发表在 电影评论, 盖世武功 | 一条评论

US States List for Ruby on Rails

def select_state_for_user
       [["","Select State..."], ["AL","Alabama"],
        ["AK","Alaska"], ["AZ","Arizona"], ["AR","Arkansas"],
        ["CA","California"], ["CO","Colorado"], ["CT","Connecticut"],
        ["DE","Delaware"], ["DC","District of Columbia"],
["FL","Florida"],

        ["GA","Georgia"], ["HI","Hawaii"], ["ID","Idaho"],
["IL","Illinois"],
        ["IN","Indiana"], ["IA","Iowa"], ["KS","Kansas"],
["KY","Kentucky"],
        ["LA","Louisiana"], ["ME","Maine"], ["MD","Maryland"],
        ["MA","Massachusetts"], ["MI","Michigan"], ["MN","Minnesota"],
        ["MS","Mississippi"], ["MO","Missouri"], ["MT","Montana"],
        ["NE","Nebraska"], ["NV","Nevada"], ["NH","New Hampshire"],
["NJ","New
        Jersey"], ["NM","New Mexico"], ["NY","New York"], ["NC","North
        Carolina"], ["ND","North Dakota"], ["OH","Ohio"],
["OK","Oklahoma"],
        ["OR","Oregon"], ["PA","Pennsylvania"], ["RI","Rhode Island"],
        ["SC","South Carolina"], ["SD","South Dakota"],
["TN","Tennessee"],
        ["TX","Texas"], ["UT","Utah"], ["VT","Vermont"],
["VA","Virginia"],
        ["WA","Washington"], ["WV","West Virginia"], ["WI","Wisconsin"],
        ["WY","Wyoming"]]
end

STATES = [
    [ "Alabama", "AL" ],
    [ "Alaska", "AK" ],
    [ "Arizona", "AZ" ],
    [ "Arkansas", "AR" ],
    [ "California", "CA" ],
    [ "Colorado", "CO" ],
    [ "Connecticut", "CT" ],
    [ "Delaware", "DE" ],
    [ "Florida", "FL" ],
    [ "Georgia", "GA" ],
    [ "Hawaii", "HI" ],
    [ "Idaho", "ID" ],
    [ "Illinois", "IL" ],
    [ "Indiana", "IN" ],
    [ "Iowa", "IA" ],
    [ "Kansas", "KS" ],
    [ "Kentucky", "KY" ],
    [ "Louisiana", "LA" ],
    [ "Maine", "ME" ],
    [ "Maryland", "MD" ],
    [ "Massachusetts", "MA" ],
    [ "Michigan", "MI" ],
    [ "Minnesota", "MN" ],
    [ "Mississippi", "MS" ],
    [ "Missouri", "MO" ],
    [ "Montana", "MT" ],
    [ "Nebraska", "NE" ],
    [ "Nevada", "NV" ],
    [ "New Hampshire", "NH" ],
    [ "New Jersey", "NJ" ],
    [ "New Mexico", "NM" ],
    [ "New York", "NY" ],
    [ "North Carolina", "NC" ],
    [ "North Dakota", "ND" ],
    [ "Ohio", "OH" ],
    [ "Oklahoma", "OK" ],
    [ "Oregon", "OR" ],
    [ "Pennsylvania", "PA" ],
    [ "Rhode Island", "RI" ],
    [ "South Carolina", "SC" ],
    [ "South Dakota", "SD" ],
    [ "Tennessee", "TN" ],
    [ "Texas", "TX" ],
    [ "Utah", "UT" ],
    [ "Vermont", "VT" ],
    [ "Virginia", "VA" ],
    [ "Washington", "WA" ],
    [ "West Virginia", "WV" ],
    [ "Wisconsin", "WI" ],
    [ "Wyoming", "WY" ]
  ].freeze

 STATES = [
    [ "", "" ],
    [ "Alabama", "Alabama" ],
    [ "Alaska", "Alaska" ],
    [ "Arizona", "Arizona" ],
    [ "Arkansas", "Arkansas" ],
    [ "California", "California" ],
    [ "Colorado", "Colorado" ],
    [ "Connecticut", "Connecticut" ],
    [ "Delaware", "Delaware" ],
    [ "Florida", "Florida" ],
    [ "Georgia", "Georgia" ],
    [ "Hawaii", "Hawaii" ],
    [ "Idaho", "Idaho" ],
    [ "Illinois", "Illinois" ],
    [ "Indiana", "Indiana" ],
    [ "Iowa", "Iowa" ],
    [ "Kansas", "Kansas" ],
    [ "Kentucky", "Kentucky" ],
    [ "Louisiana", "Louisiana" ],
    [ "Maine", "Maine" ],
    [ "Maryland", "Maryland" ],
    [ "Massachusetts", "Massachusetts" ],
    [ "Michigan", "Michigan" ],
    [ "Minnesota", "Minnesota" ],
    [ "Mississippi", "Mississippi" ],
    [ "Missouri", "Missouri" ],
    [ "Montana", "Montana" ],
    [ "Nebraska", "Nebraska" ],
    [ "Nevada", "Nevada" ],
    [ "New Hampshire", "New Hampshire" ],
    [ "New Jersey", "New Jersey" ],
    [ "New Mexico", "New Mexico" ],
    [ "New York", "New York" ],
    [ "North Carolina", "North Carolina" ],
    [ "North Dakota", "North Dakota" ],
    [ "Ohio", "Ohio" ],
    [ "Oklahoma", "Oklahoma" ],
    [ "Oregon", "Oregon" ],
    [ "Pennsylvania", "Pennsylvania" ],
    [ "Rhode Island", "Rhode Island" ],
    [ "South Carolina", "South Carolina" ],
    [ "South Dakota", "South Dakota" ],
    [ "Tennessee", "Tennessee" ],
    [ "Texas", "Texas" ],
    [ "Utah", "Utah" ],
    [ "Vermont", "Vermont" ],
    [ "Virginia", "Virginia" ],
    [ "Washington", "Washington" ],
    [ "West Virginia", "West Virginia" ],
    [ "Wisconsin", "Wisconsin" ],
    [ "Wyoming", "Wyoming" ]
  ]

发表在 Ruby on Rails | 留下评论