Javascript打开窗口 [英] Javascript Open Window

查看:116
本文介绍了Javascript打开窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄明白如何使javascript打开正确的窗口。div类.show在我的javascript控件内容我想打开。然而,如果使用多个.show,它有麻烦。



在一个页面内,我可能有很多这些.show类,根据哪一个按下,我想要一个显示。



例如

 < span class =Show> ;< a href =#>显示< / a>< / span> -  
< div class =show>
Content 1
< / div>

< span class =Show>< a href =#>显示< / a>< / span> -
< div class =show>
Content 2
< / div>

所以如果我点击顶部的显示,我会看到内容1,如果我点击第二个将会看到内容2.



当点击第一个节目内容1时提供的当前代码,将打开一个包含内容1的窗口。如果我单击第二个内容1,而不是内容2.



以下是javascript。

 < script type =text / javascript> 
$(a)。click(function(){
var html = $(show)。html();
var my_window = window.open( mywindow1,width = 350,height = 150);
$(my_window.document).find(body)。html(html);
}
< / script>任何帮助将非常感谢:)


我用这个小提琴去我的地方: http://jsfiddle.net/A72TH/

解决方案

这很脆弱,但你可以这样做:

  var html = $(this).parent()。next(div.show)。 

工作示例在这里: http://jsfiddle.net/RV86q/


I'm trying to figure out how to make the javascript open the correct window.The div class .show within my javascript controls the content I want to open. However it is having trouble if multiple .show are being used.

Within one page I may have many of these .show classes and according to which one is pressed I would like that one to show.

For example

<span class="Show"><a href="#">Show</a></span> - 
    <div class="show">
       Content 1 
    </div>

<span class="Show"><a href="#">Show</a></span> - 
   <div class="show">
      Content 2 
   </div>

So if I click on the top show I will see Content 1 and if I click on the second I will see content 2.

At the moment with the current code provided when clicking the first show "content 1" a window opens with Content 1. If I click the second Content 1 appears and not Content 2.

Below is the javascript.

<script type="text/javascript">
    $("a").click(function () {
    var html = $(".show").html();
    var my_window = window.open("", "mywindow1", "width=350,height=150");
        $(my_window.document).find("body").html(html);
    });
</script>   

Any help would be greatly appreciated :)

I used this fiddle to get to where I am : http://jsfiddle.net/A72TH/

解决方案

Well this is pretty fragile but you can accomplish it as follows:

var html = $(this).parent().next("div.show").html();

The working sample is here: http://jsfiddle.net/RV86q/

这篇关于Javascript打开窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆