讓我分享我的jQuery部分首先
$(".btnUpdateInput").click(function() {
//alert("Update");
var BldDocumentId = $("#BldDocId").val();
var BldinstructionId = $("#BldIPInstnId").val();
var InputFieldId = $("#InputFieldId").val();
var InputFieldValue = jQuery.trim($(this).parent().prev().text()); //$("#InputFieldValue").val();
var InputFieldUserValue = jQuery.trim($(this).prev().val()); // $(".user_input_value").val();
alert(BldDocumentId + "," + BldinstructionId + "," + InputFieldId + "," + InputFieldValue + "," + InputFieldUserValue);
var postResult;
alert($(this).get());
$.post("/Build/UpdateInputField",
{ bldDocId: BldDocumentId, bldInstnId: BldinstructionId, inputFieldId: InputFieldId, inputFieldValue: InputFieldValue, inputFieldUserValue: InputFieldUserValue },
function(result) {
postResult = result;
//Either this should function**
alert($(this).get()); // returned Object[Object] but expected the clicked button
alert($(this).parent().get());// returned null
alert($(this).parent().next().get());//returned null
alert($(this).parent().next().children().first().get());// returned null
// $(this).parent().next().show();
// $(this).parent().next().children().first().text(InputFieldUserValue);
// $(this).parent().hide();
});
alert(postResult);
//Or this should function**
if (postResult == true) {
$(this).parent().next().show();
$(this).parent().next().children().first().text(InputFieldUserValue);
$(this).parent().hide();
}
});
現在讓我解釋一下我的問題。我需要顯示並隱藏少數divs相對於我點擊的按鈕「btnUpdateInput」。我嘗試了兩種方式:1,我給下面的線路中的在$。員額
$.post("/Build/UpdateInputField",
{ bldDocId: BldDocumentId, bldInstnId: BldinstructionId, inputFieldId: InputFieldId, inputFieldValue: InputFieldValue, inputFieldUserValue: InputFieldUserValue },
function(result) {
postResult = result;
//Either this should function**
alert($(this).get()); // returned Object[Object] but expected the clicked button
alert($(this).parent().get());// returned null
alert($(this).parent().next().get());//returned null
alert($(this).parent().next().children().first().get());// returned null
// $(this).parent().next().show();
// $(this).parent().next().children().first().text(InputFieldUserValue);
// $(this).parent().hide();
});
2.成功的部分或得到postResult的價值出來,比較和做同樣存在。代碼如下:
if (postResult == true) {
$(this).parent().next().show();
$(this).parent().next().children().first().text(InputFieldUserValue);
$(this).parent().hide();
}
兩者都不適合我。在1上午沒有得到$(this)作爲我單擊的按鈕'btnUpdateInput',並且2. postResult的值是未定義的,因爲沒有延遲,因此postResult被分配給了post操作的結果。
請幫我解決這兩種情況。
這將是如果您也發佈了相關的HTML源代碼,這會更有幫助。 – reporter
你真的想要什麼$(this)? – rhapsodyn