【发布时间】:2021-08-31 02:13:09
【问题描述】:
我看到了很多回复,但没有一个符合我的需求。 基本上我试图通过 JavaScript 获取 href 的值,我需要将其传递给我的 django 视图,当我执行 console.log 时,这是我得到的输出
http://localhost:8000/#vert-tabs-Personal localhost:8000:316:21
#vert-tabs-Personal localhost:8000:317:21
http://localhost:8000/#vert-tabs-Career localhost:8000:316:21
#vert-tabs-Career localhost:8000:317:21
http://localhost:8000/#vert-tabs-Finances localhost:8000:316:21
#vert-tabs-Finances
这是目前触发输出的脚本
<script>
$(".nav-link").on('click', function(e){
console.log(e.target.href);
console.log(e.target.hash);
});
</script>
现在将 e.target.hash 值传递给我的 django 视图的最佳方法是什么。 我正在考虑 jquery 或 ajax 但老实说我不知道。 任何帮助,将不胜感激。 提前谢谢你...
【问题讨论】:
-
关于点击事件使用jquery ajax 调用href 和ajax 成功方法更新html 这里是jquery 中关于ajax 的文档api.jquery.com/jquery.ajax
标签: javascript django django-views