注册 登录
编程论坛 JavaScript论坛

JS菜鸟问题,请高手不吝赐教。。。

小宇u 发布于 2011-06-18 11:09, 506 次点击
如何修改下面这段代码使它变成在同一窗口打开,不要打开多个新窗口,要在同一窗口执行
<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'>
4 回复
#2
kongmajian2011-06-20 14:15
有个疑问就是 你用的checkbox是支持多选的,那么请问你多选了几个然后确定后打开的网页以哪个为准呢?还有你指的同一个窗口指的是有checkbox的这个原窗口还是另外新建的一个窗口?

[ 本帖最后由 kongmajian 于 2011-6-20 14:21 编辑 ]
#3
小宇u2011-06-22 09:08
具体以哪个为准没有要求,同一个窗口指的是有checkbox的这个原窗口
#4
小宇u2011-06-24 19:16
回复 2楼 kongmajian
以当前窗口为准,同一个窗口指的是有checkbox的这个原窗口
#5
kongmajian2011-06-29 14:25
程序代码:
<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 编辑 ]
1