在页面加载

时间:2015-11-05 13:30:14

标签: jquery html

<ul class="test">
    <li>
        <a href="abc.com">abc.com</a>
        <a href="xyz.com">xyz.com</a>
    </li>
</ul>

我们如何在页面加载的新窗口中打开上面的URL。

4 个答案:

答案 0 :(得分:1)

提供a-tags target="_blank"

<ul class="test">
    <li>
        <a href="abc.com" target="_blank">abc.com</a>
        <a href="xyz.com" target="_blank">xyz.com</a>
    </li>
</ul>

答案 1 :(得分:1)

  

使用特定选择器选择a元素,并使用window.open作为这些元素的href属性

$('a').each(function () {
    window.open(this.href);
});

答案 2 :(得分:0)

**I got the solution: Thanks to everyone for your help.**

<ul class="test">
    <li>
        <a href="abc.com">abc.com</a>
        <a href="xyz.com">xyz.com</a>
    </li>
</ul>

<script type='text/javascript' >
    $(document).ready(function(){
        $(".test li a").each(function(){
            url = $(this).attr("href");
            window.open(url,'_blank')
        });
    })
</script>

答案 3 :(得分:0)

您必须添加target="_blank"

<a href="abc.com" target="_blank">abc.com</a>
 <a href="xyz.com" target="_blank">xyz.com</a>
相关问题