0

我正在编写一个可以链接到不同网站的弹出功能。在弹出窗口中,有 3 个选择:例如 yahoo、google 等。所以对我来说,问题是我选择 yahoo 弹出窗口后如何链接到 yahoo.com.hk。

例如,我选择“yahoo”,它将打开一个新窗口并链接到 www.yahoo.com。

谢谢!

<a href="#Link" data-rel="popup">

<div data-role="popup" id="Share" data-shadow="true" data-theme="a"   >
  <fieldset data-role="controlgroup">
    <legend>Select website</legend>
    <input type="radio" name="radio-choice" id="radio-choice-1" value="yahoo"  />
    <label for="radio-choice-1">yahoo</label>

    <input type="radio" name="radio-choice" id="radio-choice-2" value="google"  />
    <label for="radio-choice-2">google</label>

    <input type="radio" name="radio-choice" id="radio-choice-3" value="microsoft"  />
    <label for="radio-choice-3">microsoft</label>
  </fieldset>
</div>
4

2 回答 2

0

当您单击灯箱中的按钮时,它将触发底层 DOM 元素上的事件。使用 jQuery 为这些 DOM 元素(单选按钮,其中元素的name属性为radio-choice)的 click 事件添加事件处理程序。

这是一个使用 jQueryUI 的灯箱(你可以使用任何你想要的灯箱)来演示的 jsFiddle:

jsFiddle

$('[name=radio-choice]').click(function() {
    var goto = $(this).val();
    if (goto == 'yahoo') {
        window.open('http://yahoo.co.uk');
    }else if(goto == 'google') {
        window.open('http://google.co.uk');
    }
});
于 2013-09-11T18:10:46.283 回答
0

只需测试 3 个单选按钮以查看它们是否被选中,如果是,则在新窗口中打开它们。

JSFiddle

var url = new Array('https://www.yahoo.com', 'https://www.google.com', 'https://www.microsoft.com');

$('#btn').click(function () {
    $('input[type="radio"]').each(function(index) {
        if ($('#radio-choice-'+(index+1)).is(':checked')) {
            window.open(url[index]);
        }
    });
});
于 2013-09-11T18:08:51.403 回答