說明如何取得 <a>
或者按鈕的外部連結 (TBD)
<!DOCTYPE html>
<html>
<head>
<title>Catch the href of the outbound link</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<style>
.lw { font-size: 60px; }
</style>
</head>
<body>
<!-- Start your code here -->
<a id="link_a" href="you_click_link">Click the link</a>
<form id="myform" action="you_submit_form">
<input type="button" value="Submit"/>
</form>
<p id="disp" class="lw"></p>
<script>
// Write JavaScript here
function showHref(event) {
event.preventDefault();
var val = event.target.href;
$("#disp").html(val);
}
function showAction(event){
event.preventDefault();
if (event.currentTarget.id == "myform") {
$("#disp").html(event.currentTarget.action);
}
}
window.onload = function () {
$("#link_a").on('click', showHref);
$("#myform").get(0).addEventListener("click", showAction, true);
};
</script>
<!-- End your code here -->
</body>
</html>