2011-08-25 32 views
0

有人可以向我解釋Form.event.findElement的jQuery等價物嗎?將原型的findElement轉換爲jQuery

$('.ad-publish-button').bind('click', function(e) { // jquery 

    // section of prototype I need to convert to jquery 
    if (e.findElement('.ad').down('form').down('#location').value != '') { 
      e.findElement('.ad').down('form').request(); 
    } 

}); 

回答

1

試試看

$('.ad-publish-button').bind('click', function(e) { 
    var _form=$('form',$(e.target).closest('.ad')[0]).first(); 
    if ($('#location',_form).val() != '') { 
     $.ajax(_form.prop('action'), {type:_form.prop('method'),data:_form.serialize()}); 
    } 
}); 
  1. e.target是點擊的元素
  2. $(e.target).closest('.ad')[0]是的className的最近的祖先從#1 'PH_1PH_1廣告' 元素的
    。此元素用作選擇器「表格」的上下文
    (因此它會在.ad元素中找到一個表單)
  3. $.ajax()將發送一個請求(使用form-屬性操作+方法和序列化元素)