Ajax下拉/最后一个选项更改Iframe

Ajax Drop Down/Last Option Changes Iframe

本文关键字:Iframe 选项 最后一个 下拉 Ajax      更新时间:2023-12-02

我现在有这个脚本,它完成了我现在想要它做的一切。它有一个下拉菜单,你可以选择goTo,你也可以选择维基百科或其他网站的列表。从那里,它将把当前存在的iFrame(例如微软)的值更改为另一个网站(例如维基百科)。

然而,我的问题是,在更改选项时,它会关闭连接并显示一个空白页面,直到我选择维基百科。我该如何解决此问题?这是我当前的代码

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title></title>
  <link href="style.css" rel="stylesheet" />
  <script src="http://code.jquery.com/jquery-2.0.3.min.js" data-semver="2.0.3" data-require="jquery"></script>
  <script type="text/javascript" src="http://www.appelsiini.net/projects/chained/jquery.chained.js?v=0.9.10"></script>
  <script>
  function goToPage763(mySelect)
  {
  PageIndex2=mySelect.selectedIndex;
  {
  if
  ( 
  mySelect.options[PageIndex2].getAttribute('href') != "none"  
  )  
  {  
  //this is the key code in the JavaScript to open the new page in  
  //the iframe:-  
  frames['iframe2'].location.href = mySelect.options[PageIndex2].getAttribute('href');  
  }  
  }  
  }
  // Add your javascript here
  $(function(){
  $("#size").chained("#color");
  });
  </script>
</head>
<body>
<form name="form763">
  <select class="form-control" id="color">
    <option value="">choose options</option>
    <option value="27">Goto</option>
    <option value="26">Nothing</option>
  </select>
  <select class="form-control" id="size" name="select763" size="1" onchange="goToPage763(this.form.select763)">
<option value="">choose options</option>
    <option value="27" class="27" href="http://www.wikipedia.com">Wiki</option>
    <option value="26" class="26">Nothing</option>
  </select>
  </form>
  <iframe name="iframe2" src="http://www.microsoft.com" align="top" height="800px" width="95%" align="middle">
</body>
</html>

看看这是否能解决问题

    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="http://code.jquery.com/jquery-2.0.3.min.js"
        data-semver="2.0.3" data-require="jquery"></script>
    <script>
          function goToPage763(mySelect){
              frames['iframe2'].location.href = $(mySelect).val();
          }
    </script>
</head>
<body>
    <form name="form763">
        <select class="form-control" id="size" name="select763"
            size="1" onchange="goToPage763(this)">
            <option value="">choose options</option>
            <option value="http://www.wikipedia.com">Wiki</option>
            <option value="http://www.microsoft.com">Microsoft</option>
            <option value="https://www.wiktionary.org/">Wiktionary</option>
        </select>
    </form>
    <iframe name="iframe2" src="http://www.microsoft.com" align="top"
        height="800px" width="95%" align="middle">
</body>
</html>