[英]How to hyperlink a select tag which open in a new tab and carry some variables
我是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添加到所有選項的data-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
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.