Javascript创建变量的html代码与一个新的日期变量
Javascript creating variable with html code with a new date variable
我不明白这里出了什么问题:
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();
}
相关文章:
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- 导航到特定事件的另一个变量页面
- 在另一个函数中使用变量this
- 我可以在Javascript/jQuery中使用一个变量作为键吗
- 使用mongodb更新中的一个变量
- 为什么window.open不打开一个以变量形式给出的链接
- 将节点数据分配给另一个变量jstree
- 如何将变量传递到另一个js文件
- 我怎么能让流星简单模式中的一个字段等于一个js变量,并且仍然让用户填写简单模式的其余部分
- 如何从onclick函数设置全局变量并将其传递给另一个JS文件
- 将会话变量从一个页面传递到另一个页面
- Javascript:在激发函数后返回一个变量以供使用
- 替换另一个变量对象中的变量值
- 什么'它的意思是当一个变量位于括号外时
- 这在JavaScript中是一个好的变量名吗
- 可以't将sessionStorage设置为Javascript中的一个变量
- 如何在javascript中给变量一个随机值
- 在不同的.js文件之间传递变量;一个是在iframe内
- Console.log(变量);VS console.log([变量]);/一个提供信息,另一个没有
- 是否可以给变量一个默认值