javascript - 如何在其他函数中获取选项id

标签 javascript jquery html model-view-controller

我有以下代码:

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/

相关文章:

javascript - Node.js puppeteer 师 "document is not defined"

javascript - 以横向模式打印页面时在哪里分页?

javascript - JQuery 过渡切换类不起作用

jQuery Mobile,HTML5,设置类型为 ="date"的输入字段

javascript - 在angularjs中从本地存储中检索对象数组

javascript - jQuery 切换、隐藏、显示 - Chrome 覆盖错误

javascript - 显示 :None destroys the rendering of other jquery objects

javascript - 弹出窗口不显示?

javascript - 使用 CSS 和 Javascript 重定向 - 手持设备

javascript - 使用 onclick - jquery 在循环中按 ID 删除元素