我有以下代码:
this.showNotificationcenter = function () {
centerNotification =
$("<div class='notificationbar'> <h2>Notificaties</h2>" +
"<ul></ul></div>");
var fullPage = $(document).find("#fullPage");
fullPage.append(centerNotification);
}
this.center = function (options) {
var notificationsUl = $(centerNotification).find("ul");
notification = $("<li id="+options.id+"><b>" + options.title + "<span class='fa fa-times'></span></b><br />" + options.content + "</li>");
notificationsUl.append(notification);
}
this.removeLi = function () {
var test = $(notification).find("id").val();
}
我使用此代码创建通知:
eformity.notification.center({
title: "Dit is een titel",
content: "Dit is een content",
id: "een",
});
我需要在函数removeLi 中获取options.id,但我不知道如何获取。 (var test 现在未定义)最终,我需要在跨度上单击事件来删除该 Li。有人能帮我吗?提前致谢。
最佳答案
您应该使用 attr
来查找属性 id 的值。
var test = $(notification).attr("id");
关于javascript - 如何在其他函数中获取选项id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33121127/