Javascript创建变量的html代码与一个新的日期变量

Javascript creating variable with html code with a new date variable

本文关键字:变量 一个 日期 创建 html 代码 Javascript      更新时间:2023-09-26

我不明白这里出了什么问题:

var $newbox = $('<div class="ui-widget-content" id="newbox-'**+noteId**'" style="top:' + e.pageY + 'px; left: ' + e.pageX + 'px;"><span id="close">Delete comment</span><p>Your comment:</p><textarea></textarea></div>');

没有这个+noteId工作得很好,有了它,firebug会给出一个丢失')'的错误…顺便说一句,这些****已经添加,所以你可以更容易地发现错误:)

下面是工作代码:

    function makeNote(e) {
    var noteDate = new date();
    var noteId = noteDate.getTime();
    // Check the event object if the .click is on the content
    // or a created note
    if (e.eventPhase === 2) {
        // Create the new comment at the corsor postition
        var $newbox = $('<div class="ui-widget-content" id="newbox" style="top:' + e.pageY + 'px; left: ' + e.pageX + 'px;"><button id="close" class="m-btn red"><i class="icon-trash"></i> Delete</button><button id="save" class="m-btn blue"><i class="icon-plus"></i> Save</button><textarea></textarea></div>');
        $('#content').append($newbox);
        if(!$newbox.draggable()){
            $newbox.draggable();
        }
    }
}
function deleteNote() {
    $(this).parent('#newbox').remove();
}
// wait until the dom document is loaded
jQuery(document).ready(function() {
    // listen for a .click() event on the content element
    $('#content').on('click', function(e){
        makeNote(e);
    })
    // Remove the note
    $("button #close").on('click',function() {
        deleteNote();
    });
});

此外,deleteNote函数不起作用,这就是为什么我必须为每个笔记创建一个唯一的id,从日期中获取时间,给出一个随机数输出…

更新2 http://s1.postimg.org/41csvbanz/Screenshot_from_2015_06_07_13_27_15.pnghttp://s18.postimg.org/j5bowucwp/Screenshot_from_2015_06_07_13_27_28.png

new date();应为大写:new Date();

这是答案,所以函数没有工作,但我弄清楚了:

$('button #close').on('click', function() {
$this.parent('#newbox').remove();
}