一尘不染

使用Javascript更改iframe src

javascript

我正在尝试更改<iframe src=... >某人单击单选按钮时的状态。由于某种原因,我的代码无法正常工作,并且我很难找出原因。这是我所拥有的:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">



<head>

  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

  <title>Untitled 1</title>



  <script>

  function go(loc) {

    document.getElementById('calendar').src = loc;

  }

  </script>

</head>



<body>

  <iframe id="calendar" src="about:blank" width="1000" height="450" frameborder="0" scrolling="no"></iframe>



  <form method="post">

    <input name="calendarSelection" type="radio" onselect="go('http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1')" />Day

    <input name="calendarSelection" type="radio" onselect="go('http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1')" />Week

    <input name="calendarSelection" type="radio" onselect="go('http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1')" />Month

  </form>



</body>



</html>

阅读 398

收藏
2020-05-01

共1个答案

一尘不染

在这种情况下,可能是因为您在此处使用了错误的括号:

document.getElementById['calendar'].src = loc;

应该

document.getElementById('calendar').src = loc;
2020-05-01