2017-07-21 2 views
1

ヘルプモードを開きたいですが、どのリンクがクリックされたかに応じて、FAQページのように特定のアンカーに焦点を当てる必要があります。我々は特定のDOM要素の表示を集中するために(hrefのリンクに例えば<a href="http://....#myAmazingTitle">FAQ</a>を#myAmazingTitleを追加します]ページで 。ブートストラップモーダルオープニングのアンカーポイント

<h1>My first title</h1> 
<h1 id="myAmazingTitle">My Amazing Title</h1> <== Display will be focused on this title 
.... 

私は、ブートストラップモーダルと同じ動作を持っていると思います。

がそれです可能性とどのように?

これは、この問題のためにFiddleです。

+0

あなたの答えのための –

+0

おかげでより多くの情報を追加したり、jsfiddle sniptを追加してください、私はそれを管理し、誰かが同じ問題を持っている場合、私はそこにjsfiddleを投稿:http://jsfiddle.net/ h3WDq/2116 / –

答えて

1

使用relatedTargetとターゲット要素のセレクターを指定する属性data-* HTML(またはアンカー)、この値をshown.bs.modalイベントのハンドラーに送信します。以下の使用例を参照してください。

$('#exampleModal').on('shown.bs.modal', function(e) { 
 
    var recipient = $(e.relatedTarget).data('focus'); 
 
    $(this).find(recipient).focus(); 
 
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
 

 
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"> 
 
    <div class="modal-dialog" role="document"> 
 
    <div class="modal-content"> 
 
     <div class="modal-header"> 
 
     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
 
     <span class="modal-title" id="exampleModalLabel">Registration form</span> 
 
     </div> 
 
     <div class="modal-body"> 
 
     <form> 
 
      <div class="form-group"> 
 
      <label for="EmailInput">Email address</label> 
 
      <input type="email" class="form-control" id="EmailInput" placeholder="Email"> 
 
      </div> 
 
      <div class="form-group"> 
 
      <label for="PassInput">Password</label> 
 
      <input type="password" class="form-control" id="PassInput" placeholder="Password"> 
 
      </div> 
 
     </form> 
 
     </div> 
 
     <div class="modal-footer"> 
 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
 
     <button type="button" class="btn btn-primary">Register</button> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div> 
 

 
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-focus="#EmailInput">Type Email</button> 
 
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-focus="#PassInput">Type Password</button>

関連する問題