2015-10-14 27 views
1

我有下面的代碼:如何獲得期權的ID在其他功能

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", 
    }); 

我需要得到options.id在函數removeLi但我不知道如何。 (var test現在是未定義的)最終,我需要一個點擊事件來刪除那個Li。有人能幫我嗎?提前致謝。

+0

http://jsfiddle.net/arunpjohny/c10gasbL/1/ –

回答

0

您應該使用attr來查找屬性ID的值。

var test = $(notification).attr("id"); 
+0

謝謝!這是行得通的。 –

+0

然後接受答案! :) –

0

要獲得標識
VAR測試= $(通知).attr( '身份證');

替換Id
var test = $(notification).attr('id','newId');