我是PHP新手。我想在用户点击选择标签的选项标签时打开一个新标签。但我失败了。请帮帮我。
这是我的代码
echo '<select name="sector_study_data" id="sector_study_data" STYLE="width: 300px">';
echo '<option value="">[--Select Sector Study2----]</option>';
if(is_array($sector_study ) && !empty($sector_study ))
{
foreach($sector_study as $sector_study)
{
echo '<option value="'.$sector_study->ID.'" href="update_sector_study.php?id='.$sector_study->ID.'"
"target="_blank"">';
//echo '<a href="http://www.w3schools.com">$sector_study->name</a>';
echo $sector_study->name;
echo '</option>';
}
}
echo '</select>';
在这里使用jquery可以实现您的需求:
1将url添加到所有选项的数据href属性中:
echo '<select name="sector_study_data" id="sector_study_data" STYLE="width: 300px">';
echo '<option value="">[--Select Sector Study2----]</option>';
if(is_array($sector_study ) && !empty($sector_study ))
{
foreach($sector_study as $sector_study)
{
echo '<option value="'.$sector_study->ID.'" data-href="update_sector_study.php?id='.$sector_study->ID.'">';
//echo '<a href="http://www.w3schools.com">$sector_study->name</a>';
echo $sector_study->name;
echo '</option>';
}
}
echo '</select>';
使用jquery:
$("#sector_study_data").change(function(){
var href = $('option:selected', this).attr('data-href'); // get href of selected option
window.open(href, '_blank'); // redirect to that href in new tab
})