我有以下从模板(jsRender)呈现的html
<div class="noteActions top" style="z-index: 3;">
<span onclick="noteAction('add', 13808, 0 );"></span>
<span onclick="noteAction('update',13808, 106344 );"></span>
<span onclick="noteAction('delete', 13808, 106344 );"></span>
</div>
我的问题是我在文档之外准备了一个函数,它正在设置一个数据数组,稍后,一个 jquery 对话框窗口通过 ajax 提交给处理程序以更新数据库
发生的事情是数据数组通过类选择器(pr-body,pr-title)正确传递了除 jquery vals 之外的所有内容,它们作为 NULL 传递
javascript - 外部文档(准备好)
var updateUrl = 'handlers/Poster.ashx',
data;
function noteAction(action, prospectID, noteID){
data = {
'operation': action,
'prospectid':prospectID,
'note-body' : $('.pr-body').val(),
'note-title' : $('.pr-title').val(),
'note-id':noteID,
};
if (action == 'add'){
$( "#dialogPostIt" ).dialog("open", "option", "title", "Add Post It");
} else if (action == 'update'){
$( "#dialogPostIt" ).dialog("open", "option", "title", "Edit Post It");
} else if (action == 'delete'){
if (!confirm('Are you sure you want to delete')) return false;
$.post(updateUrl+"?operation=delete¬eid="+noteID, function(data) {
$('#stickyNote-'+noteID).remove();
});
}
}
jquery - 准备好文档
$(document).ready(function() {
$( "#dialogPostIt" ).dialog({autoOpen: false, modal:true,
buttons: {
'Save': function() {
$.ajax({
url: updateUrl,
data: data,
success: function(json, textStatus, jqXHR){
.....
html
<div id="dialogPostIt" >
<form id="postItNow" action="" method="post" class="note-form">
<label for="note-title">Title (description)</label>
<input type="text" name="note-title" id="note-title" class="pr-title" value="" />
<label for="note-body">Text of the note</label>
<textarea name="note-body" id="note-body" class="pr-body" cols="30" rows="6"> </textarea>
</form></div>
我之前在对话框保存按钮函数()中设置数据数组,效果很好,但我需要根据事件使一些数组元素动态化
根据我的要求,数组不必是全局的,我只是想不出另一种方法来做到这一点
一如既往,非常感谢任何帮助