我有兩個html
頁面,在index.html
文件中,我有一個button
和一個input textbox
。我希望textbox
中的值顯示在下一頁上。我應該如何去做這件事,我應該有兩個JavaScript文件?或者是什麼?JavaScript/jQuery在其他html頁面中添加innerHtml
的Javascript:
$('#searchBtn').click(function(){
var search = document.getElementById('searchField');
document.getElementById("demo").innerHTML = search.value;
});
的Index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/index.css" type="text/css" />
<title>The Lantzyfi Bay</title>
</head>
<body>
<div class="head">
<img class="logo" src="pics/logo.png">
</div>
<div class="body">
<form>
<div class="searchField">
<input id="searchField" type="text" placeholder="Lantzify Search" name="search" size="32"/>
<a id="searchBtn" class="search" href="results.html">Search</a>
</div>
<div class="checkboxes">
<input type="checkbox" name="music">Music</input>
<input type="checkbox" name="pics">Pics</input>
<input type="checkbox" name="videos">Videos</input>
<input type="checkbox" name="other">Other</input>
</div>
</form>
<div class="links">
<a href="#">Userpolicy</a>
<a href="#">About</a>
<a href="#">Lorem Ipsum</a>
</div>
</div>
<script type="text/javascript" src="java/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="java/search.js"></script>
</body>
</html>
results.html:
<!DOCHTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/index.css" type="text/css" />
<link rel="stylesheet" href="css/results.css" type="text/css" />
<title>The Lantzyfi Bay</title>
</head>
<body>
<div class="head">
<form id="q">
<a href="index.html"><img class="logo" src="pics/logo.png"></a>
<input id="searchField" type="text" placeholder="User serch" name="search" size="30"/>
<a id="searchBtn" class="search" href="results.html">Search</a>
</form>
</div>
<div class="content">
<h2>Serach: <!--Users Search word--></h2><h2 id="demo"></h2>
<div class="mainContent">
<table>
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>DB</th>
<th>RP</th>
</tr>
</thead>
<tr>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
</tr>
<tr>
<td>Test</td>
<td>Test</td>
<td>Test</td>
<td>Test</td>
</tr>
</table>
</div>
</div>
<script type="text/javascript" src="java/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="java/search.js"></script>
</body>
</html>
不 - 你不能這樣做,JavaScript運行在一個頁面內,你改變頁面,JavaScript不見了 –