0

jQueryを学び始めました。ポップアップ ウィンドウを作成し、その上にボタンを追加します。そのボタンをクリックしてポップアップ ウィンドウを閉じたいのですが、ID を使用してウィンドウをアタッチしましたが、機能しません。ご協力ありがとうございました。

<a href="" rel="0" class="patrick" >click me</a>

var windowSizeArray = ["width=200,height=200", "width=3000,height=400,scrollbars=yes"];

$(document).ready(function () {
    $('#win').bind('click', function () {
        newwindow.close();
    });
    var $newdiv1 = $('<input type="button" class="myButton" value="ok" id="win"/>')

    $('.patrick').click(function (event) {
        var url = $(this).attr("href");
        var windowName = "popUp"; //$(this).attr("name");
        var windowSize = windowSizeArray[$(this).attr("rel")];

        var newwindow = window.open(url, windowName, windowSize);
        event.preventDefault();
        $(newwindow.document.body).html($newdiv1);
    });


});
4

1 に答える 1

1

インライン JS はあまり使用しないでください。この場合、インライン JS をボタンに追加するだけが最も簡単な解決策です。

var windowSizeArray = ["width=200,height=200", "width=3000,height=400,scrollbars=yes"];

$(document).ready(function () {
    var $newdiv1 = $('<input type="button" class="myButton" value="ok" id="win" onclick="window.close()"/>')

    $('.patrick').click(function (event) {
        var url = $(this).attr("href");
        var windowName = "popUp"; //$(this).attr("name");
        var windowSize = windowSizeArray[$(this).attr("rel")];

        var newwindow = window.open(url, windowName, windowSize);
        event.preventDefault();
        $(newwindow.document.body).html($newdiv1);
    });
});

フィドル

于 2013-06-16T17:28:27.650 に答える