| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 506 人关注过本帖
标题:JS菜鸟问题,请高手不吝赐教。。。
只看楼主 加入收藏
小宇u
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-6-18
结帖率:0
收藏
已结贴  问题点数:0 回复次数:4 
JS菜鸟问题,请高手不吝赐教。。。
如何修改下面这段代码使它变成在同一窗口打开,不要打开多个新窗口,要在同一窗口执行
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
/*
bb=[];
bb[1]=['asdf'];
alert(bb[1]);

str=JSON.parse('<?php echo json_encode(array ('a'=>'0','b'=>2,'c'=>3,'d'=>4,'e'=>5));?>');
for(k in str)
    document.write(str[k]+"<br/>");

a=[];
for(i in a)
document.write(i);
document.write(a.length);*/

function modalDialog(url, name, width, height)
{
  if (name==undefined)
  {
      name='_blank';
  }
  if (width == undefined)
  {
    width = 400;
  }
  if (height == undefined)
  {
    height = 300;
  }
      x = (window.screen.width - width) / 2;
    y = (window.screen.height - height) / 2;

    window.open(url, name, 'height='+height+', width='+width+', left='+x+', top='+y+', toolbar=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, modal=yes');

}
function je_open()
{
    url=[];
    url[0]='http://www.baidu.com/';
    url[1]='http://www.baidu.com/';
    url[2]='http://mp3.baidu.com/';
    url[3]='http://zhidao.baidu.com/';
    url[4]='http://nes.baidu.com/';
    url[5]='http://www.baidu.com/';
    url[6]='http://www.baidu.com/';
    je_elem=document.forms['a'].elements;
   
    for(i=0;i<url.length;i++)
    {
        if (je_elem[i].checked)
            modalDialog(url[i]);
    }
        //document.getElementById('txt').innerHTML+=i+':'+je_elem[i].checked+'<br />';
        
    return false;
}

</script>
<form name="a" onsubmit="return je_open();">
<p><input type="checkbox"><a herf="http://www.baidu.com/">baidu</a></p>
<br/>
<p><input type="checkbox">baidu</p><br/>
<p><input type="checkbox">baidu</p><br/>
<p><input type="checkbox">baidu</p><br/>
<p><input type="checkbox">baidu</p><br/>
<p><input type="checkbox">baidu</p><br/>
<p><input type="checkbox">baidu</p><br/>
<input type="submit" type="button" value="确定">
</form>
<span id='txt'>
搜索更多相关主题的帖子: function content 
2011-06-18 11:09
kongmajian
Rank: 2
等 级:论坛游民
帖 子:13
专家分:30
注 册:2011-6-19
收藏
得分:20 
有个疑问就是 你用的checkbox是支持多选的,那么请问你多选了几个然后确定后打开的网页以哪个为准呢?还有你指的同一个窗口指的是有checkbox的这个原窗口还是另外新建的一个窗口?

[ 本帖最后由 kongmajian 于 2011-6-20 14:21 编辑 ]
2011-06-20 14:15
小宇u
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-6-18
收藏
得分:0 
具体以哪个为准没有要求,同一个窗口指的是有checkbox的这个原窗口
2011-06-22 09:08
小宇u
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-6-18
收藏
得分:0 
回复 2楼 kongmajian
以当前窗口为准,同一个窗口指的是有checkbox的这个原窗口
2011-06-24 19:16
kongmajian
Rank: 2
等 级:论坛游民
帖 子:13
专家分:30
注 册:2011-6-19
收藏
得分:0 
程序代码:
<html>
    <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript">
/*
bb=[];
bb[1]=['asdf'];
alert(bb[1]);

str=JSON.parse('<?php echo json_encode(array ('a'=>'0','b'=>2,'c'=>3,'d'=>4,'e'=>5));?>');
for(k in str)
    document.write(str[k]+"<br/>");

a=[];
for(i in a)
document.write(i);
document.write(a.length);*/

function modalDialog(url, name, width, height)
{
  if (name==undefined)
  {
      name='_blank';
  }
  if (width == undefined)
  {
    width = 400;
  }
  if (height == undefined)
  {
    height = 300;
  }
      x = (window.screen.width - width) / 2;
    y = (window.screen.height - height) / 2;

    //window.open(url, name, 'height='+height+', width='+width+', left='+x+', top='+y+', toolbar=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, modal=yes');
    window.location.href=url;
}
function je_open()
{
    url=[];
    url[0]='http://www.baidu.com/';
    url[1]='http://www.baidu.com/';
    url[2]='http://mp3.baidu.com/';
    url[3]='http://zhidao.baidu.com/';
    url[4]='http://nes.baidu.com/';
    url[5]='http://www.baidu.com/';
    url[6]='http://www.baidu.com/';
    je_elem=document.forms['a'].elements;
   
    for(i=0;i<url.length;i++)
    {
        if (je_elem[i].checked)
            modalDialog(url[i]);
    }
        //document.getElementById('txt').innerHTML+=i+':'+je_elem[i].checked+'<br />';
       
    return false;
}

</script>
</head>
<body>
<form name="a" onsubmit="return je_open();">
<p><input type="checkbox"><a herf="http://www.baidu.com/">baidu</a></p>
<br/>
<p><input type="checkbox">baidu</p><br/>
<p><input type="checkbox">baidu</p><br/>
<p><input type="checkbox">baidu</p><br/>
<p><input type="checkbox">baidu</p><br/>
<p><input type="checkbox">baidu</p><br/>
<p><input type="checkbox">baidu</p><br/>
<input type="submit" type="button" value="确定">
</form>
<span id='txt'>
</body>
</html>
窗口大小没有变动,要变动的话自己加参数。

[ 本帖最后由 kongmajian 于 2011-6-29 14:26 编辑 ]
2011-06-29 14:25
快速回复:JS菜鸟问题,请高手不吝赐教。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018512 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved