嗨,我有这个javascript代码工作正常。这是一个选择员工姓名的下拉菜单。然后它会自动指向leave_approve_process.php
,它将显示有关该员工的任何相关信息。
但是,如何更改代码以便在新标签页中打开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>
答案 0 :(得分: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找到更多相关答案。