2013-05-07 14 views
0

我正在創建一個包含大量靜態HTML頁面的網站(例如:1.html,2.html,3.html .....等等)。當用戶在此文本框中輸入特定頁碼時,每個頁面都有一個文本框,它們必須重定向到該特定頁面。假設用戶在文本框中輸入數字13,然後按輸入它必須重定向到13.html。如何讀取文本框中的值並添加一些擴展

P.S:建議使用HTML + JS或任何前端的組合。

回答

1

試試這個:

$('#textboxid').change(function(){ document.location.href = $(this).val()+'.html';}) 
+0

非常感謝這是我尋找的解決方案 – Thejdeep 2013-05-07 13:12:46

1

您可以使用此代碼,你將不得不改變選擇,以符合您輸入:

$("input").keydown(function(e) { 
    if (e.which == 13) { 
     location.href = this.value + ".html"; 
    } 
}); 

演示:http://jsfiddle.net/ahW62/

0

試試這個

$("body").keydown(function(e) { 
    if (e.which == 13) { 
     location.href = $('#textboxid').val()+ ".html"; 
    } 
}); 
0

嘗試,

<html> 
<head> 
<title>Test</title> 
</head> 
<body> 
<input type="text" id="txt" /> 
<input type="button" onclick="redirect()" value="redirect" /> 

<script type="text/javascript"> 
    function redirect() { 
     var url = document.getElementById("txt").value; 
     window.location.href = url + "html"; 
     } 
</script> 
</body> 
</html> 
相關問題