我有_PartialLayout页面如下
_PartialLayout.cshtml
@foreach (var item in ViewBag.listGroups)
{
string idvalue = item.ID.ToString();
switch (idvalue)
{
case "1":
<div class="gp-sub1">
<p class="hidden" id="gplineid">@item.ID</p>
<h4><a id="gpline" href='#' class="gp1 open" data-staion="GP_LINE">@item.GroupName</a></h4>
</div>
break;
}
...
}
这是_Layout Page
_Layout.cshtml
<!DOCTYPE html>
<html>
<head>
</head>
<body class="ss">
@Html.Partial("_PartialLayout")
</body>
</html>
<script type="text/javascript">
$(document).ready(function () {
$("#gpline").click(function () {
alert($('#gplineid').val());
});
});
</script>
在partilview布局中,gpline
点击我尝试按上述gplineid
,但这不会提示任何结果:(
答案 0 :(得分:0)
实际上我可以在@Stephen的帮助下获得价值,如下所示
@foreach (var item in ViewBag.listGroups)
{
string idvalue = item.ID.ToString();
switch (idvalue)
{
case "1":
<div class="gp-sub1">
<p class="hidden" id="gplineid" data-groupid="@item.ID">@item.ID</p>
<h4><a id="gpline" href='#' class="gp1 open" data-staion="GP_LINE">@item.GroupName</a></h4>
</div>
break;
}
...
}
然后在_Layout页面
$("#gpline").click(function () {
alert($(this).closest('.gp-sub1').find("#gplineid").attr("data-groupid"))
});
答案 1 :(得分:-1)
试
$("#gplineid").html();
或
$("#gplineid").text();
答案 2 :(得分:-1)
你可以尝试
$("#gpline").live("click",function () {
alert($('#gplineid').val());
});