带有无线电选择的Javascript无法正常工作

时间:2018-01-24 01:06:39

标签: javascript jquery

我错过了什么吗?该按钮应该基于无线电选择启动各个站点



  
function navigateSite(){
  var getUrl = document.querySelector('input[name = "myRadio"]:checked').value
  console.log(getUrl);
}

 <INPUT TYPE="radio" id="Orange" name="myRadio" value="www.google.com"> Orange
 <INPUT TYPE="radio" id="Apple" name="myRadio" value="www.mozilla.com"> Apple
 <INPUT TYPE="radio" id="Mango" name="myRadio" value="www.microsoft.com"> Mango
 <button onclick="navigateSite()">Select</button> 
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

弹出窗口仅在代码段之外工作

&#13;
&#13;
  
function navigateSite(){
  var getUrl = document.querySelector('input[name = "myRadio"]:checked').value
  console.log(getUrl);
  window.open(getUrl, getUrl, "width=600,height=500");
}
&#13;
 <INPUT TYPE="radio" id="Orange" name="myRadio" value="www.google.com"> Orange
 <INPUT TYPE="radio" id="Apple" name="myRadio" value="www.mozilla.com"> Apple
 <INPUT TYPE="radio" id="Mango" name="myRadio" value="www.microsoft.com"> Mango
 <button onclick="navigateSite()">Select</button> 
&#13;
&#13;
&#13;