我有一个 html 按钮,应该在按钮单击时触发 javascript。它识别按钮单击并显示确认警报,但不会继续并发布 console.logs 或进入 ajax 方法。这是javascipt函数:
$('.Delete')
.click(function() {
return confirm("Are you sure you'd like to delete this entry?"
if(return = true)
{
var parent = $(this).parent().prev();
var tr = $(this).closest('tr');
var ValNode = tr.find(".typeText").first();
var AddrNode = parent.children(".AddrText").first();
var Val = ValNode.val();
var addr = addrNode.val();
console.log(Val);
console.log(addr);
var item = { Value: Val, Address: addr }
deleteItem(userID, item);
}
});
这是html元素,我认为它可能与按钮与其调用的元素的关系有关。我把他们当作堂兄弟。
<asp:ListView runat="server" id="ListView1" >
<LayoutTemplate>
<thead>
<tr>
<th>
<a href="#">Type</a>
</th>
<th>
<a href="#">Address</a>
</th>
</tr>
</thead>
<tbody>
<tr id="itemPlaceholder" runat="server" />
</tbody>
<tfoot>
</tfoot>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<input type="text" id="Type" class="TypeText " value="<%# Eval("Type")%>" />
<input type="text" id="Addr" class="AddrText " value="<%# Eval("Address")%>" />
</td>
<td>
<input type="button" id="btn_update" class="Update" value="Update" />
<input type="button" id="btn_delete" class="Delete" value="Delete" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>