此刻我正在建立一个网站,而我在获取div ID时遇到了问题,单击div按钮包含按钮的位置。
<div id="div" class="tab-content" title="Foods">
<div class="container">
<div class="row">
<div class="col-lg-2">
<div class="tabs-block">
<asp:Button ID="btnSend" runat="server" OnClick=""/>
</div>
</div>
</div>
</div>
</div>
</div>
这不是我的代码,而是类似的代码。 我要这样做的是,当我单击btnSend按钮时,我需要获取标签内容ID和标题为“ food”的内容,我试图使用javascript和jquery来获取标题,然后在其上使用它后台代码是
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
string message = "";
message += "<p>"Title here" Resevation Form </p><br />";
{
}
我需要在后台代码“ Title here”上使用该标题
答案 0 :(得分:1)
您应该这样写:
<div class="col-lg-2">
<div class="tabs-block" name="Title">
<Button ID="btnSend" runat="server"/>
</div>
</div>
$( "#btnSend" ).click(function(event) {
console.log($(this).parent().attr("name"))
});
在$(this).parent()。attr(“ name”)中,您将具有单击的选项卡的名称。