为什么不是't我为这个函数定义的javascript函数
Why isn't my javascript function defined for this function?
这是非常一致的,但firebug显示我的saveForm函数不是从我的"button.save"事件处理程序中定义的,但它适用于我的"utton.deleteForm"事件处理:
function saveForm(form)
{
var $form = form;
var url = $form.attr('action');
$.ajax({
type: "POST",
enctype: 'mutipart/form-data',
url: url,
data: $form.serialize(), // serializes the form's elements.
success: function(data)
{
// data is the server response.
// change this function to tell the
// user whether their submission
// is correct or what fields have
// bad data.
var response = JSON.parse(data);
return true;
}
});
return false; // avoid to execute the actual submit of the form.
}
// Do not use event handlers like .click(). This is the
// only viable solution for handling events on dynamically
// generated HTML elements. This handles the saving of data
// to the server.
$(document).on('click', 'button.save', function(e){
var $form = $(this).closest('form');
saveForm(form);
});
// This event handler is responsible for deleting data.
// For Joey's job: Please make sure that this calls save
// after the user hits delete. This will save the data in
// the database.
$(document).on('click', 'button.deleteForm', function(e){
// Get the form to update before deleting our embedded form
var $form = $(this).closest('form');
var str = $(this).attr('id');
// Get the table id in review to delete
var deleteForm = str + '_review';
$('table#' + deleteForm).remove();
// Get the collection form id to delete
var idArray = str.split('_');
idArray.pop();
divId = '#' + idArray.join('_');
$(divId).remove();
saveForm($form);
});
您在保存表单中错过了$
$(document).on('click', 'button.save', function(e){
var $form = $(this).closest('form');
saveForm($form);
//------^----here
});
相关文章:
- 用嵌套函数和默认函数定义函数
- 使用Extjs进行函数定义
- JS中奇怪的函数定义语法
- 重写javascript函数定义
- 使用角度图时,我可以用函数定义数据点颜色吗
- modal.js中的匿名函数定义
- 为从AJAX调用中utlizes DATA参数的函数定义回调
- Emacs:在 etag 中查找函数定义
- Javascript:对象函数定义
- 为什么要在函数定义之外引用静态变量(函数属性)
- Ember 对象函数定义中的计算属性.js
- javascript/jQuery中函数定义的区别
- CoffeeScript 承诺与函数定义链接
- 如何在使用 eval() 评估 JavaScript 时将回调函数定义作为参数传递
- Javascript - 为什么下面的函数定义错误
- 使用函数声明时的自定义函数(也称为惰性函数定义)
- JavaScript 函数定义不正确
- jQuery off on 时是用匿名函数定义的
- 停止 IntelliJ 11 在启用 JSLint 时向每个嵌套函数定义添加“use strict”
- 为什么不是't我为这个函数定义的javascript函数