我是js的新手。 我試圖抓住textbox
的值並在新頁面中顯示。 但不知何故,當我點擊按鈕時,它顯示了一秒鐘的值,然後重定向到相同的表單頁面。 請告訴我我在哪裏做錯了?謝謝。 這裏是我的代碼javascript open()方法衝突
HTML
<div id="myDiv">
<strong>Enter your name in the box below, then click
the button to see a personalized page!</strong>
<br>
<form id="newp" onsubmit="newpage();">
Name: <input type="text" id="yourname" size="25">
<br><br>
<input type="submit" onclick="pressedbutton()" value="Submit">
</form>
<script type="text/javascript" src="main.js"></script>
</div>
JS
function pressedbutton()
{
var thename = document.getElementById("yourname").value;
document.open();
document.write("<h1>Welcome!</h1>");
document.write("Hello, " + thename + ", and welcome to my page!");
document.close();
}
感謝。
如何使用數據在新頁面中顯示??像新的HTML文件? –
有多種方式,它取決於您可以使用的工具(例如服務器端語言)。總的來說,這取決於你想要對數據做什麼。 –
我的意思是在這個頁面,我正在編碼,它是否正在創建一個新的頁面? –