搜索栏仅在我输入并点击输入时有效但如果我从其他网站复制一个单词并粘贴它,它将不会搜索除非我点击它编辑(通过放置空格然后删除空格)然后我就可以按回车键了。我添加了脚本,所以人们不会只是输入它是空的,但现在我认为它弄乱了搜索栏。我怎么能复制并粘贴一个单词而不必编辑它?
修改:
<form action='/search.php' method='GET'>
<input id='searchbar' type='text' name='search' placeholder="search for movies & shows" maxlength="50" required />
<input id='submit' type='submit' name='submit' value='Search' disabled />
</form>
<script>
document.getElementById('searchbar').onkeypress = function() {
document.getElementById('submit').disabled = !this.value.trim();
}
</script>
答案 0 :(得分:1)
试试这个
document.getElementById('searchbar').oninput = function() {
document.getElementById('submit').disabled = !this.value.trim();
}