2015-11-30 258 views
1

嗨我有這個JavaScript代碼,工作正常。這是一個選擇員工姓名的下拉菜單。然後它會自動指向leave_approve_process.php,這將顯示有關員工的任何相關信息。Javascript在新標籤頁打開鏈接

但是,如何更改代碼,以便它將在新選項卡中打開leave_approve_process.php。請幫助我,因爲我是新來的這個JavaScript。謝謝。

$employee = mysqli_query("SELECT * FROM employee"); 

<script type="text/javascript"> 
function showUser() 
{ 
    var str1=document.getElementById('employee').value; 
    if (str1=="") 
    { 
     document.getElementById("txtHint").innerHTML=""; 
     return; 
    } 
    if (window.XMLHttpRequest) 
    {// code for IE7+, Firefox, Chrome, Opera, Safari 
     xmlhttp=new XMLHttpRequest(); 
    } 
    else 
    {// code for IE6, IE5 
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
     xmlhttp.onreadystatechange=function() 
    { 
     if (xmlhttp.readyState==4 && xmlhttp.status==200) 
     { 
      document.getElementById("txtHint").innerHTML=xmlhttp.responseText; 
     } 
    } 
    xmlhttp.open("GET","leave_approve_process.php?id="+str1,true); 
    xmlhttp.send(); 
} 
</script> 

<form name="form2" id="form2" method="post" action=""> 
<select name="employee" id="employee" onChange="showUser()" class="validate[required]"> 
    <option value="">Select one</option> 
    <?php 
    while($row_sem=mysqli_fetch_array($employee)) 
    {  
     echo "<option value='". $row_sem['emp_id'] ."'>". $row_sem['emp_name'] ."</option>";   
    } 
    ?> 
</select> 
</form> 
<br /> 
<div id="txtHint" align="center"></div> 

回答

1

創建一個新函數並從當前函數中調用它。

function OpenInNewTab("leave_approve_process.php?id="+str1,true) { 
    var win = window.open("leave_approve_process.php?id="+str1,true, '_blank'); 
    win.focus(); 
} 

如果我的答案對您沒有幫助,您可以在Open a URL in a new tab (and not a new window) using JavaScript找到更多相關答案。

相關問題