Web サイトに Jquery ダイアログ ボックスがあります。このダイアログ ボックスは、ユーザーのコメントを取得するためのものです。現在、次のコードを使用して Javascript 関数を実行しており、正常に動作しています。
**<a href="#dialog" name="modal">Rate this</a>**
<div id="dialog" class="window"></div>
<div id="mask"></div>
次のように呼び出すJavascriptコード:
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({ 'width': maskWidth, 'height': maskHeight });
//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow", 0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH / 2 - $(id).height() / 2);
$(id).css('left', winW / 2 - $(id).width() / 2);
//transition effect
$(id).fadeIn(2000);
});
});
//if close button is clicked
$("input[id$='btnClose']").click(function(e) {
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
href にはサーバー側のクリック イベントがないため、リンク ボタンを使用して JavaScript を呼び出す必要があります。いくつかの方法を試しましたが、実際の結果を得ることができませんでした。
**<a href="#dialog" name="modal">Rate this</a>**
結論として、クリック イベントをトラップできるように、この呼び出しをリンク ボタンに変更する必要があります。