0
function RequestTickets(url) {
var settings = 'height=500,width=400,location=no,resizable=no,scrollbars=no,status=no,
    titlebar=yes,toolbar=no';
var newwindow = window.open(url, '-- Ticket Request Form --', settings, false);
if (window.focus) { newwindow.focus() };
return false;
}

上記の javascript は、umbraco ページの次の html コードによって呼び出されます。

<a href="javascript:RequestTickets('/us/home/requestform.aspx')">here</a> to request tickets for an event.

newwindow が定義されていないという javascript エラーが発生し続けます。私はそれを明確に定義したので、なぜそれが起こり続けるのか混乱しています! 助けてください

4

1 に答える 1

1

通常、html要素とjavascript関数の間のバインディングは、htmlではなくaddEventListener(ほとんどの場合jQueryイベントを使用)を介してjavascriptで作成します。

document.getElementById('action-request-tickets').addEventListener('click', function(event){
    event.preventDefault();

    var settings = 'height=500,width=400,location=no,resizable=no,scrollbars=no,status=no,titlebar=yes,toolbar=no';
    var newwindow = window.open(this.href, '-- Ticket Request Form --', settings, false);
    if (window.focus) { 
        newwindow.focus() 
    };
    return false;
});

http://jsfiddle.net/DvHnP/

利点: この関数は this (id action-request-tickets を持つ要素) から href を取得するため、再利用できます。

于 2013-10-31T14:23:29.103 に答える