简体   繁体   中英

How to link button to another page referring to specific tab?

I had a list of tab on view_profil page:

 <div class="panel panel-default">
<ul class="nav nav-pills" id="mytab">
  <li class="active"><a data-toggle="tab" href="#profil">Profil</a></li>
  <li><a id="keluarga-tab" data-toggle="tab" href="#keluarga">Keluarga</a></li>
  <li><a id="kursus-tab" data-toggle="tab" href="#kursus">Kursus</a></li>
  <li><a id="akademik-tab" data-toggle="tab" href="#akademik">Akademik</a></li>
  <li><a id="anugerah-tab" data-toggle="tab" href="#anugerah">Anugerah</a></li>
</ul>

I want to link a button from other page to this page but referring to 'keluarga' tab directly.

I used this code for the button:

<a href="{{ url('/view_profil/' . $valueItemregistrationkeluarga->ItemRegistrationID.'#keluarga') }}" class="btn btn-warning btn-md">Back</a>

I had tried using a few jquery code and javascript but fail..What is the right javascript/jquery for this purpose?

This is jquery used ;

<script>
var hash = document.location.hash;
if (hash) {
$('.nav-tabs a[href='+hash+']').tab('show');
} 

// Change hash for page-reload
$('.nav-tabs a').on('shown.bs.tab', function (e) {
window.location.hash = e.target.hash;
});
</script>

I had tried numerous script before, this is the latest...

I am using laravel 5 for this application.

But still fail..anyone can help?

Actually where to put this javascript code? in page with the tabs targeted or from the button page?

Use the following link

<a href="{{ url('view_profil')}}/{{$valueItemregistrationkeluarga->ItemRegistrationID}}/#keluarga" class="btn btn-warning btn-md">Back</a>

wrap your code in a document ready statement

<script>
$(function(){
var hash = document.location.hash;
if (hash) {
$('.nav-tabs a[href='+hash+']').tab('show');
} 

// Change hash for page-reload
$('.nav-tabs a').on('shown.bs.tab', function (e) {
window.location.hash = e.target.hash;
});
})
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM