**Page <input type="text" id="page#" value={{Page_id}} style="width:50px; display:inline-block" > out of {{total}}
<input type="button" class="btn btn-outline-success" onclick="getDirection()" value="Go" style="display:inline">
<script>
function getDirection(){
var input = document.getElementById("page#").value;
var new_id ="http://159.203.172.178/page/{{current_page.id_tei}}" ;
new_id = new_id.slice(0,-3);
new_id = new_id+input;
console.log(new_id);
window.location=new_id;
}
**
你好,我是 JavaScript 新手。我试图让我的 django 应用程序接受用户的输入并根据他们的输入转到页面。现在,当我单击“Go”按钮时它就可以工作。有没有办法让它在我按下 Enter 键时也能工作?我尝试使用 EventListener,但它告诉我 EvetListener 不是一个函数。万分感谢。
最佳答案
您可以将其设为表单并将该函数称为“onSubmit”。
关于javascript - 使按 Enter 键与 onclick 相同 ="function()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50992211/