JAVASCRIPT條件語句

2013-04-22 3:11 am
我想問下如果用Dreamweaver做條件語句的話,但係個條件語句係用係個文本欄位度,咁應該將編碼放係邊?仲有,係用普通文本欄位定Spry個種文本欄位?

回答 (1)

2013-04-28 4:59 pm
✔ 最佳答案
普通的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>


收錄日期: 2021-04-13 19:25:30
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20130421000051KK00324

檢視 Wayback Machine 備份