1
我使用jeditable來更新頁面上的多個項目,但是有一些不同的記錄可以在一個頁面上修改,所以我需要傳遞唯一的ID每條記錄都伴隨着更新。每條記錄都包含在自己的div中,記錄ID爲id。獲取包含div的ID在jable的jQuery中傳遞
我已經設法讓jquery工作,但它獲得第一個div的ID而不是包含div。
這裏是簡化
<div id="outer">
<div id="left">
<div id="3">
<p><strong>Web ID: </strong>3</p>
<p><strong>Record Date type (008): </strong><span class="editable_select" id="0085" style="display: inline">eng</span></p>
<p><strong>Collection ID (035): </strong>(WlAbNL)1002</p>
<p><strong>Date Created (260): </strong><span class="click" style="display: inline" id="260">1910 -</span></p>
</div>
</div>
</div>
HTML和這裏是工作Jquery的,但選擇 '外部',而不是 '3'。我認爲問題出在我的var rec定義中?
<script id="source" language="javascript" type="text/javascript">
$(document).ready(function() {
var recid = $('.click').closest('div').attr('id');
$('.click').editable('ajax/save.php', {
cancel : 'Cancel',
submit : 'OK',
indicator : 'Saving...',
style : "inherit",
tooltip : 'Click to change...',
submitdata : function() {
return {rid : recid };
}
});
$('.edit_area').editable('ajax/save.php', {
submitdata : {record: "<?php echo $rec_id; ?>"},
type : 'textarea',
cancel : 'Cancel',
submit : 'OK',
indicator : '<img src="img/indicator.gif">',
tooltip : 'Click to change...'
});
$(".editable_select").editable('ajax_save.php', {
submitdata : {record: "<?php echo $rec_id; ?>"},
indicator : '<img src="img/indicator.gif">',
data : "{'Eng':'Eng','Cym':'Cym'}",
type : "select",
submit : "OK",
style : "inherit",
});
});
更新 -
下現在得到正確的ID,我不得不改變VAR使用功能。
我想通了。而不是隻是試圖設置recid我需要專注的功能,所以這個工程。
var recid;
$('.click').focus(function() {
recid = $(this).closest('div').attr('id');
});
但是因爲我有觸發此(點擊,edit_area,editable_select)三類是可以用別的東西代替「點擊」所以它適用於任何使用它的editables的?或者我需要重複上述?
我確實嘗試過,但它出來的是相同的'外'。我認爲它的Var(JS新手)中的'click'位是錯誤的。我也嘗試過這種方式,而且沒有任何回報,我需要知道它在哪裏,如果這是有道理的。我會更新我的問題 – 2012-08-10 10:39:12