javascript 使用 jQuery 在另一个窗口中打开页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16845905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 06:12:46  来源:igfitidea点击:

Open page in another window (abrir pagina en otra ventana) with jQuery

javascriptjqueryhtml

提问by aquinoaldair

The code below opens pagina.phpin the same page, but I want to open it in another window.

下面的代码pagina.php在同一页面中打开,但我想在另一个窗口中打开它。

(Como abrir pagina en otra ventana con jquery?El siguiente codigo me abre la pagina.phpdentro de la misma pagina lo que yo quiero es abrirla en otra ventana.)

如何使用jquery在另一个窗口中打开一个页面?下面的代码pagina.php在同一个页面中为我打开它,我想要的是在另一个窗口中打开它。

<html>
<head>
<script type="text/javascript" src="jquery-1.10.0.min.js"></script>
<script language="JavaScript" type="text/JavaScript">
   $(document).ready(function(){
        $("#select1").change(function(event){
            var id = $("#select1").find(':selected').val();
           $(location).attr('href','pagina.php?id='+id);         
        });
    });
</script>
</head>
 <body>
      <select name="select1" id="selec#1"> 
        <option value='1'>opcion una </option>
     </select>
 </body>
</html>

回答by acdcjunior

Instead of (en lugar de):

代替:

$(location).attr('href','pagina.php?id='+id); 

Use (utilizar):

利用:

window.open('pagina.php?id='+id,'_blank');









Your code corrected (el código corregido):

您的代码已更正:

<html>
<head>
<script type="text/javascript" src="jquery-1.10.0.min.js"></script>
<script language="JavaScript" type="text/JavaScript">
 $(document).ready(function(){
   $("#select1").change(function(event){
      var id = $("#select1").find(':selected').val();
      window.open('pagina.php?id='+id,'_blank');  // changed here (cambiado aquí)
    });
 });
</script>
</head>
<body>
   <select name="select1" id="select1">     <!-- changed here (cambiado aquí) -->
      <option value='1'>opcion una</option>
      <option value='2'>opcion dos</option> <!-- changed here (cambiado aquí) -->
   </select>
 </body>