0
그래서 jquery와 같은 테이블 html이 있다고 가정 해 보겠습니다.Jquery로 숨겨진 요소 값 선택
클릭 저장에있는 groupid 값을 찾고 싶습니다.
내가
<table border="0" id="tableJoinList" cellpadding="4" cellspacing="5">
<tr><td colspan="3" align="left" style="padding-bottom:7px">
<img src="../../Content/Images/doublelinegray.jpg" alt="doublelinegray.jpg" width="480px" height="4px" />
</td></tr>
@foreach (var item in Model.Groups)
{
<tr>
<td>
@Html.ActionLink("Join", "Join", new { id = item.GroupID }, new { @class = "Join" })
@Html.Hidden("groupid", item.GroupID, new { @class = "groupid" })
</td>
<td align="left">
@item.GroupName
</td>
<td>
@item.DateAdded
</td>
</tr>
}
<tr><td colspan="3" align="left">
<img src="../../Content/Images/doublelinegrayreverse.jpg" alt="doublelinegrayreverse.jpg" width="480px" height="4px" />
</td></tr>
</table>
<script type="text/javascript">
$(function() {
$(".Join").live("click", function() {
var html = "<tr><td colspan='3'>Enter Password: <input type='password' class='pwd' />";
html += " <input type='button' class='Save' value='Save' /></td></tr>";
$(this).closest("tr").after(html);
$(".Save").live("click", function() {
alert($(this).siblings(".pwd").val());
var json = { Password: $(this).siblings(".pwd").val(), GroupID: $(this).prev("tr").find(".groupid").val() };
alert($(this).parent("tr").prev("tr").children(".groupid").val());
return false;
$.ajax({
url: "/Group/ConfirmPassword",
type: "POST",
dataType: 'json',
data: JSON.stringify(json),
contentType: "application/json; charset=utf-8",
success: function (result) {
if (result.Success == true)
window.location.href = result.Url;
else
alert(result.ErrorMessage);
return false;
}
});
});
return false;
});
});
</script>
일부 HTML이 누락되었다고 생각합니다. 저장 버튼은 어디에 있습니까? 당신의 문제가'$ (this) .parent ("tr"). prev ("tr")에있을 수 있기 때문에 행과 어떻게 관련이 있는지 알게 될 것입니다 children (". groupid")'올바르게 타겟팅되지 않았습니다. . 오, 최종 HTML을 공유하십시오. – Mottie
저장 버튼은 가입 클릭 자바 스크립트에 있습니다. – Malcolm