一,使用document.write()
二,使用window方法,prompt(),alert()和confirm()
<html lang="en">
<head>
<title>Search example</title>
<script type="text/javascript">
function checkSearch()
{
if(!document.getElementById||!document.createTextNode){return;}
if(!document.getElementById('search')){return;} //通过元素的ID特性来获取元素
var searchValue=document.getElementById('search').value;
if(searchValue=='')
{
alert('Please enter a search term');
return false;
}
else if(searchValue=='JavaScript')
{
var really=confirm('"JavaScript" is tt very common term.\n'+
'Do you really want to search for this?');
return really;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form action="sitesearch.php" method="post" onsubmit="return checkSearch()">
<p>
<label for="search">Search the site:</label>
<input type="text" id="search" name="search"/>
<input type="submit" value="Search"/>
</p>
</form>
</form>
</body>
</html>