2016-07-22 64 views
1

我正在嘗試將焦點設置爲隱藏div元素內的錨元素,同時單擊另一個錨點鏈接。我嘗試了幾個選項,如.focus(),.focusin()。但沒有任何工作。將焦點設置在展示後的div內部?

我的代碼:

<script> 
    $(document).ready(function(){ 
     $("#clickShow").on('click', function(){ 
      $("#showDescription").show(); 
      $("#showDescription").find("a").focus(); 
     }); 
    }); 
</script> 
<div> 
    <a href="#" id="clickShow">View Hidden Text</a> 
</div> 

<div id="showDescription" style="display:none;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap <a href="#">Link Text</a> into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div> 

我想知道,我是缺少在這裏把它做?

感謝您的尊敬的幫助。

回答

1

其實它的工作!使用jQuery的2.1.1

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<script> 
 
    $(document).ready(function(){ 
 
     $("#clickShow").on('click', function(){ 
 
      $("#showDescription").show(); 
 
      $("#showDescription").find("a").focus(); 
 
     }); 
 
    }); 
 
</script> 
 
<div> 
 
    <a href="#" id="clickShow">View Hidden Text</a> 
 
</div> 
 

 
<div id="showDescription" style="display:none;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap <a href="http://www.google.com">Link Text</a> into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>

編輯:在1.11.1試過太...它的工作... 也許你的問題是別的東西

+0

其實我使用的應用程序jQuery 1.11.1版本。是否有任何可能性來完成這個功能。 – Maniram

+0

也試過在1.11.1中......它的工作......也許你的問題是別的 – kukkuz