我正在嘗試實現Todo列表的內聯編輯。我有這個代碼,我希望能夠獲得它的價值。如何在jQuery中獲取.html()內的值
$(function clickedit() {
$(".a").dblclick(function (e) {
e.stopPropagation();
var currentEle = $(this);
var value = $(this).html();
var id_val = $(this).attr('value');
//alert(id_val);
updateVal(currentEle, value, id_val);/**/
});
});
function updateVal(currentEle, value, id_val) {
$(currentEle).html('<input class="thVal" id="aaa" type="text" value="' + value + '" />'); // i want to get the value inside the input
var aaa = $('#aaa').val();
$(".thVal").focus();
$(".thVal").keyup(function (event) {
if (event.keyCode == 13) {
alert(aaa);
$.post('includes/edit-task3.php', { task_name: aaa, task_id: id_val}, function() {
$(currentEle).html($(".thVal").val().trim());
alert('in');
//current_element.parent().fadeOut("fast", function() { $(this).remove(); });
});
}
});
$(document).click(function() {
$(currentEle).html($(".thVal").val().trim());
});
}
如何獲取.html()中輸入的當前值?
我試過,var aaa = $('#aaa').val();
但它不起作用..我該怎麼做?
非常感謝您的幫助。
'$(currentEle).find( '#AAA')觸發的功能。VAL( );'試試這個 – guradio
你做了這個被黑客入侵的版本'var aaa = value'; – madalinivascu
@madalinivascu,或者只是使用'價值':P – Rayon