✔ 最佳答案
普通的OK(小弟未用過spry :P)
實際情況要看你的語句是怎樣的。
雖然放在不同地方的this不同,不過反正document是absolute address,放在哪裡都一樣可以用。:D
Example 1:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>I hate giving titles to documents</title>
</head>
<body>
<script>
function welcome(){
if(document.getElementById("name").value == "Peter"){
alert("I hate you, Peter! Please go away!");
} else {
alert("Welcome to my web page, " + document.getElementById("name").value) + ".";
}
}
</script>
<p>Write your name here:</p>
<input id="name" type="text"/>
<button onclick="welcome();">Welcome</button>
</body>
</html>
Example 2:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>I hate giving titles to documents</title>
</head>
<body>
<p>Write your name here:</p>
<input id="name" type="text"/>
<button onclick="if(document.getElementById('name').value == 'Peter') alert('I hate you, Peter! Please go away!');
else alert('Welcome to my web page, ' + document.getElementById('name').value) + '.';">Welcome</button>
</body>
</html>