选择菜单 - Onclick弹出窗口

时间:2011-02-12 20:07:50

标签: javascript html

我有一个HTML选择菜单,其中包含一些带链接的选项。当我点击一个选项时,它会打开链接(使用以下javascript):

function MM_jumpMenu(targ,selObj,restore)
{
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}

使用此html选择菜单:

<select name="actions" id="actions" onchange="MM_jumpMenu('parent',this,0)">
<option value="./external_link.html">External Link</option>
<option value="./external_link2.html">External Link2</option>
</select>

现在,我的问题是:如果选择菜单是这样的话我怎么能这样做(注意有一个弹出窗口链接),如果单击弹出窗口选项,弹出一个小窗口?

<select name="actions" id="actions" onchange="MM_jumpMenu('parent',this,0)">
<option value="./external_link.html">External Link</option>
<option value="./popup_window.html">Popup Window</option>
</select>

谢谢!

1 个答案:

答案 0 :(得分:0)

如果选择的文字以 Pop

开头,则会弹出链接
function MM_jumpMenu(targ,selObj,restore) {
  var target = selObj.options[selObj.selectedIndex].text.indexOf('Pop')==0)?"_blank":"_"+targ; 
  window.open(selObj.options[selObj.selectedIndex].value,target);
  if (restore) selObj.selectedIndex=0;
}

大小:

function MM_jumpMenu(targ,selObj,restore) {
  var pop = selObj.options[selObj.selectedIndex].text.indexOf('Pop')==0);
  var parms = (pop)?"width=500,height=500":""; 
  var target =(pop)?"_blank":"_"+targ;
  window.open(selObj.options[selObj.selectedIndex].value,target,parms);
  if (restore) selObj.selectedIndex=0;
}

在选项中使用目标:

function popOrNot(selObj,restore) {
  var parms = "width=500,height=500"; 
  var opt = selObj.options[selObj.selectedIndex].value.split(':');
  var target =opt[0];
  var loc = opt[1];
  window.open(loc,target,parms);
  if (restore) selObj.selectedIndex=0;
}

<select name="actions" id="actions" onchange="popOrNot(this,0)">
<option value="_parent:./external_link.html">External Link</option>
<option value="_blank:./popup_window.html">Popup Window</option>
</select>