텍스트 상자에서 입력을 받아 해당 입력을 사용하여 URL로 사용자를 안내하는 JavaScript를 찾고 있습니다. 그것은 www.mywebsite.com/users/123.html에 당신을 데려 갈 것이다, "123"을 입력 할 때 _______특정 스크립트 작성에 도움이 필요합니다.
제출하고 제출을 클릭 :
는 ID를 입력합니다.
텍스트 상자에서 입력을 받아 해당 입력을 사용하여 URL로 사용자를 안내하는 JavaScript를 찾고 있습니다. 그것은 www.mywebsite.com/users/123.html에 당신을 데려 갈 것이다, "123"을 입력 할 때 _______특정 스크립트 작성에 도움이 필요합니다.
제출하고 제출을 클릭 :
는 ID를 입력합니다.
<html>
<body bgcolor="silver">
<div class="align-center" >
<h2> Re-Direction</h2>
</div>
<label>Enter Your Search Interest</label>
<input type="text" id="data"/></br>
<!-- input type="text" would help you to create a box which would accept a user value -->
<div class="align-center"><button onclick="redirection()">Click Me</button></div>
<!-- in the above line we attach a JS function redirection to the button -->
</body>
<script>
function redirection(){
//document.getElementById("data") would search for the html element with id="data" which in our case is input element
var tempData = document.getElementById("data");
//window.location.href would help you with redirection to the desired url
window.location.href = 'https://en.wikipedia.org/wiki/'+tempData.value;
//window.location.href="your urli.e www.mywebsite.com/users/"+tempData.value;
}
</script>
</html>
너는 그 사람이야! 고마워 친구! –
문제 없습니다. 도와 줄 수있어서 기뻐 –
양식을 작성하고 제출하기 전에 양식을 변경하는 한 가지 방법이 있습니다.
(function() {
var form = document.querySelector("form.js-form");
if (form instanceof HTMLFormElement) {
var text = form.querySelector("input[type='text']");
if (text instanceof HTMLInputElement) {
form.addEventListener("submit", function (evt) {
form.action = "www.mywebsite.com/users/" + text.value + ".html";
});
}
}
})();
<form action="javascript:void(0)" method="GET" class="js-form">
<input type="text" placeholder="Insert a user Id" />
<input type="submit" value="submit" />
</form>
(function() {
var text = document.querySelector(".js-text");
var submit = document.querySelector(".js-button");
if (text instanceof HTMLInputElement && submit instanceof HTMLButtonElement) {
submit.addEventListener("click", function (evt) {
window.location.replace("www.mywebsite.com/users/" + text.value + ".html");
});
}
})();
<input type="text" placeholder="Type an Id" class="js-text" />
<button class="js-button">Submit</button>
고맙지 만 제출 버튼을 눌렀을 때 아무런 조치도 취하지 않았습니다 –
스크립트가 실행 중이고 오류가 없는지 확인하십시오 (빨간색 오류가있는 콘솔 확인) –
괜찮음 내가 오프라인으로 작업 중이기 때문에 그렇지 않을까요? –
무슨 코드를 시도? 이것은 매우 사소한 것으로 보이며 Google을 사용하여 찾을 수 있습니다. – Matt
누군가 추천 한 스크립트를 사용해 보았지만 작동하지 않습니다. 그것은 번호 추가"../fans/${num}.html 경우 = 123 대신에 www.mywebsite.com/users/123.html –
나는 현재 그것을 찾고, 나는 당신이 내가 무엇을 찾고 찾을 수있는 링크를 걸릴거야. –