我有一個輸入,在某些點恰好有焦點。如果用戶點擊頁面的「背景」,則輸入失去焦點。我試圖用下面的代碼模擬背景上的點擊,但這不起作用(你會注意到輸入仍然有焦點)。有關如何編寫模擬點擊頁面「背景」的代碼的任何建議?如何模擬點擊以使當前輸入失去其焦點與JavaScript
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/yahoo/yahoo-min.js" ></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/event/event-min.js" ></script>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function() {
document.getElementById("input").focus();
document.getElementById("main").focus();
});
</script>
</head>
<body>
<div id="main">
<form action="/">
<p>
<input type="text" id="input"/>
</p>
</form>
</div>
</body>
</html>
好東西,謝謝保羅。我應該考慮一下:)。 – avernet 2008-10-22 23:04:50