【发布时间】:2016-09-17 14:58:15
【问题描述】:
我是 PHP 新手。当用户单击“选择标记选项值”时,我想打开新选项卡。 这是我的代码
<td> <select name="select_ss" id="select_ss" STYLE="width: 300px" onchange="open_window(this.value)">
<option value="">[--Select Sector Study------]</option>
<?php
if(is_array($getAllSectorStudys) && !empty($getAllSectorStudys))
{
foreach($getAllSectorStudys as $getAllSectorStudy)
{
echo '<option value="'.$getAllSectorStudy->ID.'" data-href="test.php?id='.$getAllSectorStudy->ID.'">';
/*echo '<option value="'.$getAllSectorStudy->ID.'"';
echo '>';*/
echo $getAllSectorStudy->name;
echo '</option>';
}
}
?>
</select>
这里是 JavaScript
<script>
function open_window(myid)
{
$("#select_ss").change(function(){
var href = $('option:selected', this).attr('data-href');
window.open(href, '_blank');
})
};
</script>
在我的代码中我有一个错误。当我第一次单击选项标签时。代码不起作用。但我第二次点击它打开的新标签。请帮我删除我的错误
【问题讨论】:
-
你试过在选项中使用
<a href="/test.php...">标签吗? -
是的,我试过了,但没用
标签: javascript php jquery