我有几个参数传递给一个js函数(我使用jeditable)。传递最接近的元素的ID作为参数值jquery
$('.edit_area').editable('update.php',{
id : '2',
type : 'textarea'
});
.edit_area是
<p>
元件。我需要将'id'的值作为最接近父元素<div>
的值 传递。
任何帮助,将不胜感激。谢谢!
我有几个参数传递给一个js函数(我使用jeditable)。传递最接近的元素的ID作为参数值jquery
$('.edit_area').editable('update.php',{
id : '2',
type : 'textarea'
});
.edit_area是
<p>
元件。我需要将'id'的值作为最接近父元素<div>
的值 传递。
任何帮助,将不胜感激。谢谢!
如果你只有一个.edit_area
元素在页面
$('.edit_area').editable('update.php', {
id: $('.edit_area').closest('div').att('id'),
type: 'textarea'
});
如果你有多个元素
$('.edit_area').each(function(){
var $this = $(this);
$this.editable('update.php', {
id: $this..closest('div').att('id'),
type: 'textarea'
});
})
尝试
$('#2').parents('div:eq(0)').attr('id'); //where 2 is your param
有几个错别字,但工作! –