2014-04-21 55 views
1

HTML標籤按鍵:焦點圖像按鈕通過jQuery的上不工作

<div class="large-9 columns"> 
    <input type="text" class="txtsearchbox" name="txtsearch" id="txtsearch" placeholder="Search" /> 
</div> 
<div class="large-3 columns"> 
    <a class="button expand" id="btnsearch1"> 
    <img src="/Content/Images/search-16x16.png" id="btnsearch" /></a> 
</div> 

JS:

$('#txtsearch').on('keydown', function (e) { 
     //debugger; 
     var keyCode = (window.event) ? e.which : e.keyCode; 
     if (keyCode == 9) { 
      e.preventDefault(); 
      $('#btnsearch1').focus(); 
      // console.log(e.target.href); 
     } 
    }); 

這裏我有一個文本框和圖像按鈕。對Tab鍵按對焦點不轉換法或顯示在圖像按鈕上..我沒有得到什麼確切的問題。

回答

2

刪除javascript,並將tabindex =「0」添加到「a」標籤。

<div class="large-9 columns"> 
    <input type="text" class="txtsearchbox" name="txtsearch" id="txtsearch" placeholder="Search" /> 
</div> 
<div class="large-3 columns"> 
    <a tabindex="0" class="button expand" id="btnsearch1"> 
     <img src="/Content/Images/search-16x16.png" id="btnsearch" /> 
    </a> 
</div>