javascript从选中的复选框中检索输入值,并在同一网页中显示多个html文件
javascript Retrieve input value from a selected checkbox and display multiple html file in same webpage
当前,当选中所有复选框时,此代码会打开4个新选项卡,但我需要在单个窗口或单个html文件或类似文件中打开所有4个页面结果(4 html)文件,有人能帮我吗?
function submit() {
var box1 = document.getElementById('box1');
var box2 = document.getElementById('box2');
var box3 = document.getElementById('box3');
var box4 = document.getElementById('box4');
var urls = [];
if (box1.checked) {
urls.push(box1.value);
}
if (box2.checked) {
urls.push(box2.value);
}
if (box3.checked) {
urls.push(box3.value);
}
if (box4.checked) {
urls.push(box4.value);
}
urls.forEach(function(url) {
goToUrl(url);
});
}
function goToUrl(url) {
var win = window.open(url, '_blank');
}
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="no-j-boxes.js"></script>
</head>
<body>
<input type="checkbox" name="box1" value="http://box1url.com" id="box1"><label>box1</label><br/>
<input type="checkbox" name="box2" value="http://box2url.com" id="box2"><label>box2</label><br/>
<input type="checkbox" name="box3" value="http://box3url.com" id="box3"><label>box3</label><br/>
<input type="checkbox" name="box4" value="http://box4url.com" id="box4"><label>box4</label><br/>
<input type="button" value="Submit" name="submitButton" onclick="submit()">
</body>
</html>
这里是html
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="no-j-boxes.js"></script>
</head>
<body>
<input type="checkbox" name="box1" value="http://box1url.com" id="box1"><label>box1</label><br/>
<input type="checkbox" name="box2" value="http://box2url.com" id="box2"><label>box2</label><br/>
<input type="checkbox" name="box3" value="http://box3url.com" id="box3"><label>box3</label><br/>
<input type="checkbox" name="box4" value="http://box4url.com" id="box4"><label>box4</label><br/>
<input type="button" value="Submit" name="submitButton" onclick="submit()">
<div id="your_div_where_you_put_all_iframes"></div>
</body>
</html>
这是脚本
<script>
function submit() {
var box1 = document.getElementById('box1');
var box2 = document.getElementById('box2');
var box3 = document.getElementById('box3');
var box4 = document.getElementById('box4');
var urls = [];
if (box1.checked) {
urls.push(box1.value);
}
if (box2.checked) {
urls.push(box2.value);
}
if (box3.checked) {
urls.push(box3.value);
}
if (box4.checked) {
urls.push(box4.value);
}
urls.forEach(function(url) {
goToUrl(url);
});
}
function goToUrl(url) {
$('<iframe src="'+url+'" frameborder="0" scrolling="no" ></iframe>').appendTo('#your_div_where_you_put_all_iframes');
}
</script>
尝试像这样附加iframe。希望它能有所帮助!
相关文章:
- 在网页上显示当前股票报价
- HTML 5 和 3.js 代码不会在网页上显示任何内容
- 使用服务器上的HTML/js在网页上显示图像
- 如何删除在PHP中打印网页时显示的URL
- 如何使用JavaScript函数在网页中显示PHP变量
- 更改当前网页上显示的部分(即不是全部)文本
- javascript从选中的复选框中检索输入值,并在同一网页中显示多个html文件
- 如何让网页显示一次,并且不再向用户显示
- 有效的网页显示在WebKit浏览器和IE中,但不显示在Firefox中
- 使用延迟加载会使我的网页显示得更快吗?
- 如何将网页显示为警报
- 网页显示使用Angular1.4的表达式中的大括号
- 如何保持网页显示期间JavaScript警报在Chrome &FireFox的一个VB ASP.. NET web应用程
- JS成功添加了一个标签,但网页显示失败
- 如何让一个网页显示在另一个网页
- 将外部网页显示为网页
- 使网页显示为完全加载,或jQuery到MooTools的翻译
- 如何从覆盖得到URL,如果网页显示在覆盖
- 外部JS文件导致我的网页显示为空白
- 为什么不是't我的网页显示时间(javaScript)