データベースのコンテンツに基づいて動的に生成されたリンクがあります。
リンクは最終的に次のようになります
<ul>
<li><a href="/Updates/LoadArticle?NewsId=3" id="article">Article 3</a></li>
<li><a href="/Updates/LoadArticle?NewsId=2" id="article">Article 2</a></li>
<li><a href="/Updates/LoadArticle?NewsId=1" id="article">Article 1</a></li>
</ul>
私がまとめたスクリプトは
$(document).ready(function () {
$("#article").click(function (e) {
InitializeDialog($("#news"), $(this).attr("href"));
e.preventDefault();
$("#news").dialog("open");
});
//Method to Initialize the DialogBox
function InitializeDialog($element, page) {
$element.dialog({
autoOpen: true,
width: 400,
resizable: false,
draggable: true,
title: "Update",
modal: true,
show: 'fold',
closeText: 'x',
dialogClass: 'alert',
closeOnEscape: true,
position: "center",
open: function (event, ui) {
$element.load(page);
},
close: function () {
$(this).dialog('close');
}
});
}
});
これは、リストの最初の記事で機能します。ダイアログは開きますが、それ以外の記事は別のページで開きます。これは、IDが一意ではないためだと思います。
私の質問は、任意の ID (たとえば、article1、article2 など) の汎用 jQuery 関数を作成する方法です。
私は jQuery で約 20 分間のトレーニングを行ったので、暗闇の中でどこを見ればよいかを撮影しています。
ありがとう。