打開頁面光標自動定位


1.實現打開某頁面光標自動定位在input的內容區:

2.實現點擊取消清除input輸入內容

此為html代碼

<div class="search">
                <input type="search" class="search-input input_search_key" placeholder="搜索" id="in" style="padding-left:1.5rem;padding-right: 1rem;">
               <span id="ospan" style="font-size:20px; position: absolute; margin:0.3rem -1.3rem; cursor: pointer" onclick="clearInput()">×</span>
                <a class="search-cancel" href="questionA.html">取消</a>
                 <div class="search_suggest " id="gov_search_suggest">
                 <ul>
                 </ul>
                 </div>
            </div>

此為js代碼:

   $(document).ready(function () {
            $("#in").focus();
        });       

        function clearInput() {
            document.getElementById('in').value = '';
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM