我不明白这里有什么问题:
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给出了一个错误的错误&#39;)... btw thesse ****已添加,所以你可以更容易发现错误:)< / p>
这是工作代码:
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,从日期开始给出一个随机数输出...
UPDATE2 http://s1.postimg.org/41csvbanz/Screenshot_from_2015_06_07_13_27_15.png http://s18.postimg.org/j5bowucwp/Screenshot_from_2015_06_07_13_27_28.png
答案 0 :(得分:1)
new date();
应为大写:new Date();
答案 1 :(得分:0)
这是答案,所以功能没有用,但我想出来了:
$('button #close').on('click', function() {
$this.parent('#newbox').remove();
}