我一直在到处寻找这个没有任何运气。如果您在iPhone上访问google.com时将精力集中在搜索字段上,则在右侧始终会出现一个小“ x”,如果触摸它,它将清除该字段的当前值。有人知道如何做到这一点吗?
我使用了Safari中的开发菜单,并将用户代理更改为iPhone。在Google上查看源代码,看起来他们已经像这样设置了html:
<div class="gp2"> <input class="gp7" id="query" type="text" name="q" size="30" maxlength="2048" autocorrect="off" autocomplete="off" /> <a class="clear" id="clearQuery" href="#"> <img src="data:image/gif;base64,R0lGODlhAQABAID%2FAMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D" alt="" /> </a>
并正在使用此javascript:
function initClearQueryLink(query,clearQuery){ clearQuery.setAttribute("title","Clear"); clearQuery.addEventListener("mousedown",clearQueryBox,true); query.addEventListener("keyup",_handleClearQueryLink,false) } function _handleClearQueryLink(){ var query=document.getElementById("query"); var clearQuery=document.getElementById("clearQuery"); if(clearQuery) if(query.value.length>0){ clearQuery.style.display="inline"; clearQuery.style.visibility="visible" } else{ clearQuery.style.display="none"; clearQuery.style.visibility="hidden" } } function clearQueryBox(event){ var query=document.getElementById("query"); var clearQuery=document.getElementById("clearQuery"); query.value=""; clearQuery.style.display="none"; clearQuery.style.visibility="hidden"; hideSuggest(); if(event)event.preventDefault() }