问题描述
没关系,我已经受够了喵喵叫……这是更简单的:
function doSearch() {
if (document.getElementById( 'query' ).value.length == 0) {
alert( 'Please enter the search!' )
document.getElementById( 'query' ).focus()
} else {
location.href = 'https://www.google.com/search?q=' + document.getElementById( 'query' ).value
}
}
因此,JavaScript 代码“抓取”带有 id 查询的元素,并检查它是否为空,如果是,则显示 alert( 'Please enter the search!' )
,然后对自身产生 focus
效果>
<!DOCTYPE html>
<html>
<head></head>
<body>
<input type="text" placeholder="Search gallico..." id="query">
<button onclick="doSearch()">GO!</button>
</body>
</html>
在 HTML 代码中,您只能看到,那将在我的搜索中! (稍后我会添加一个标志)
度过美好的一天!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)