這裏是我的代碼:如何獲得點擊元素的href值?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.rawgit.com/makeusabrew/bootbox/master/bootbox.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<a onclick="return bootbox.confirm('are you sure?', function(e){ if (e) {window.location = this.href;} });" href="/Remove-Post/{{ $tb }}/{{$post->id}}" data-toggle="modal" data-target="#confirm-delete">Link</a>
注意到我使用this library爲confirm
。
,但此行並不在我的代碼工作:
window.location = this.href;
,它總是(當我點擊OK)重定向我在這裏:
http://localhost:8000/undefined
如何解決它?
$ tb未定義。你使用任何模板引擎或框架? –
難道你不使用e.target代替這個嗎? – Aer0
你可以做一個js小提琴嗎? @stack –