這是從edit-in-place-using-ajax直電梯,但它不工作。誰能建議爲什麼?保存按鈕和取消按鈕都不會做任何事情。我認爲saveButton和cancelButton單擊時不會觸發分配給其單擊事件的jquery代碼。編輯jquery網站上描述的地方不起作用
<script src="/jscript/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#editInPlace").click(function(){
var textarea = '<div><textarea rows="5" cols="30">' + $(this).html() + '</textarea>';
var button = '<div><input type="button" value="SAVE" class="saveButton" /> OR <input type="button" value="CANCEL" class="cancelButton"/></div></div>';
var revert = $(this).html();
$(this).after(textarea+button).remove();
});
$('.saveButton').click(function(){saveChanges(this, false);});
$('.cancelButton').click(function(){saveChanges(this, revert);});
function saveChanges(obj, cancel) {
if (!cancel) {
var t = $(obj).parent().siblings(0).val();
alert('new text='+t);
}else {
var t = revert; //orig code had cancel;
}
$(obj).parent().parent().after('<div id="editInPlace">'+t+'</div>').remove()
}
});
</script>
<div id='editInPlace'>we are going to change this comment.</div>
添加對@nbrook圖像(基於他建議的代碼)....
初始顯示 - 首先點擊>
- >
上第二次點擊內textarea - >
這是繼續...
沒有幫助。它仍然沒有做任何事情點擊任何按鈕。 – rajeev
@rajeev請創建一個jsFiddle,我會看看我是否可以跟蹤這個問題。 –