<分区>
标签 javascript c# html css
<分区>
我目前正在构建一个网站,但在单击 div 按钮包含按钮的按钮上获取 div id 时遇到了问题。
<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 和标题“食物”,我尝试使用 javascript 和 jquery 获取标题,然后我将在我的上使用它后台代码是
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
string message = "";
message += "<p>"Title here" Resevation Form </p><br />";
{
}
我需要在背景代码中使用那个标题,即“Title here”
最佳答案
你应该这样写:
<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") 中,您将拥有您点击的选项卡的名称。
关于javascript - 获取按钮上的 div 的 id 单击 div 包含该按钮的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57057013/