html5怎么通过输入指定文字跳转指定界面
就是用户输入指定文字,跳转指定界面
如:
用户在输入框输入bing,跳转到https://bing.com/
用户在输入框输入google,跳转到https://google.com/
<html>
<head>
<meta charset="UTF-8">
<title>跳转</title>
</head>
<body>
<form>
<label for="search">输入关键字:</label>
<input type="text" id="search" name="search">
<button type="submit">搜索</button>
</form>
</body>
<script language="javascript">
const form = document.querySelector('form');
form.addEventListener('submit', function(event) {
event.preventDefault();
const searchInput = document.querySelector('#search');
window.location.href = 'https://'+searchInput.value+'.com/';
});
</script>
</html>
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!