shi*_*juo 83 javascript iframe src
当有人点击单选按钮时,我正在尝试更改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>Run Code Online (Sandbox Code Playgroud)
Pek*_*ica 115
在这种情况下,可能是因为你在这里使用了错误的括号:
document.getElementById['calendar'].src = loc;
Run Code Online (Sandbox Code Playgroud)
应该
document.getElementById('calendar').src = loc;
Run Code Online (Sandbox Code Playgroud)
ine*_*nja 57
也许这可能会有所帮助...这是简单的HTML - 没有javascript:
<p>Click on link bellow to change iframe content:</p>
<a href="http://www.bing.com" target="search_iframe">Bing</a> -
<a href="http://en.wikipedia.org" target="search_iframe">Wikipedia</a> -
<a href="http://google.com" target="search_iframe">Google</a> (not allowed in inframe)
<iframe src="http://en.wikipedia.org" width="100%" height="100%" name="search_iframe"></iframe>Run Code Online (Sandbox Code Playgroud)
顺便说一下,有些网站不允许你在iframe中打开它们(安全原因 - 点击劫持)
在onselect必须onclick.这适用于键盘用户.
我还建议<label>在"Day","Month"和"Year"的文本中添加标签,以便更容易点击.示例代码:
<input id="day" name="calendarSelection" type="radio" onclick="go('http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1')"/><label for="day">Day</label>
Run Code Online (Sandbox Code Playgroud)
我还建议删除属性onclick和值之间的空格,尽管它可以被浏览器解析:
<input name="calendarSelection" type="radio" onclick = "go('http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1')"/>Day
Run Code Online (Sandbox Code Playgroud)
应该:
<input name="calendarSelection" type="radio" onclick="go('http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1')"/>Day
Run Code Online (Sandbox Code Playgroud)
这也应该有效,尽管src意志保持不变:
document.getElementById("myIFrame").contentWindow.document.location.href="http://myLink.com";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
394393 次 |
| 最近记录: |