努力的目标按钮
问题描述:
嗨,我尝试使用iframe来针对一个按钮,一个div ..我想了这么多,但没有结果......努力的目标按钮
<html>
<body>
<div id="one">
<button type="submit" onclick="ShowResult()" formtarget="result"> Calculate </button>
</div>
<div id="two">
<iframe name="result"></iframe>
</div>
</body>
的javascript:
function ShowResult()
{
document.write("someword");
}
这似乎是真的,但当我点击按钮,它打开一个空白页面,显示什么在功能..帮助??
答
你缺少了很多,
- 先不要练
"onclick()"
了。 - 其次不再练习
"document.write"
了。
我重写代码,享受..
HTML
<div id="one">
<button type="submit" id="functionThis" formtarget="result"> Calculate </button>
</div>
<div id="two">
<iframe id="iframe1" name="result"></iframe>
</div>
JS
document.getElementById("functionThis").addEventListener("click", showResult, false);
function showResult() {
var htmlString = "<body>Some Words</body>";
var myIFrame = document.getElementById('iframe1');
myIFrame.src = "javascript:'" + htmlString + "'";
}
小提琴
+0
它没有为我工作,但谢谢你.. –
+0
这是在小提琴的工作,我已经在我的本地尝试过它也工作过。你能告诉我你有什么错误吗?因为它在任何地方工作 –
将formtarget替换为目标。 –
不起作用:/ –