我有一个div标签,里面有一个链接标签,如代码所示。该链接仅在我点击它时才有效。但我想以这样的方式编写代码,即使我点击div标签,也应该转到链接。请帮忙,因为我是javascript的初学者。
<div id="blockbuilding">
<a id="@data.bbuildingid" href="@Url.Action("Overview","Overview", new{BuildingId=@data.buildingID})" class="buildingAnchor""> @data.buildingName </a>
</div>
答案 0 :(得分:0)
试试这个
$(document).ready(function () {
$("#blockbuilding").click(
function () {
AlertSave();
}
);
});
function AlertSave() {
alert("Alert Message OnClick");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="blockbuilding">
<a id="@data.bbuildingid" href="@Url.Action("Overview","Overview", new{BuildingId=@data.buildingID})" class="buildingAnchor""> @data.buildingName </a>
</div>