2017-05-04 40 views
0

是否可以使用PHP文件中的腳本打開導航標籤(php文件是外部)。我試着用這一個echo "<script>alert('success')open('colors.php#yellow','_self')</script>";直接到頁面,它會打開一個導航標籤與黃Twitter Bootstrap:使用腳本從PHP打開導航標籤

的ID我有這個HTML

<div class="container"> 

<!--------> 
<div id="content"> 
    <ul id="tabs" class="nav nav-tabs" data-tabs="tabs"> 
     <li class="active"><a href="#red" data-toggle="tab">Red</a></li> 
     <li><a href="#orange" data-toggle="tab">Orange</a></li> 
     <li><a href="#yellow" data-toggle="tab">Yellow</a></li> 
     <li><a href="#green" data-toggle="tab">Green</a></li> 
     <li><a href="#blue" data-toggle="tab">Blue</a></li> 
    </ul> 
    <div id="my-tab-content" class="tab-content"> 
     <div class="tab-pane active" id="red"> 
      <h1>Red</h1> 
      <p>red red red red red red</p> 
     </div> 
     <div class="tab-pane" id="orange"> 
      <h1>Orange</h1> 
      <p>orange orange orange orange orange</p> 
     </div> 
     <div class="tab-pane" id="yellow"> 
      <h1>Yellow</h1> 
      <p>yellow yellow yellow yellow yellow</p> 
     </div> 
     <div class="tab-pane" id="green"> 
      <h1>Green</h1> 
      <p>green green green green green</p> 
     </div> 
     <div class="tab-pane" id="blue"> 
      <h1>Blue</h1> 
      <p>blue blue blue blue blue</p> 
     </div> 
    </div> 
</div> 

PHP open_color.php

echo "<script>alert('success')open('colors.php#yellow','_self')</script>" 

我的輸出仍然是紅色標籤將打開爲活動狀態

回答

0

W帽子這一個:

open_color.php:

$val = $_REQUEST['some_var']; 

    switch ($val) { 
     case 'red': 
      header("Location: colors.php#red"); 
      break; 

     . . . 

     default: 
      header("Location: colors.php"); 
      break; 
    } 
+0

謝謝大家的答案先生,但是沒有它不工作連'Location'碼 –

相關問題