[英]OnClick HTML button : call Javascript function + location.href (Django)
How can I put 2 operations in my onclick parameter, one calling a Javascript function, the other giving location.href with Django tags ? 如何在onclick参数中进行2个操作,一个操作调用Javascript函数,另一个操作给Django标签提供location.href? I want to make something appear on the page before redirecting to another page.
我想让某些东西出现在页面上,然后再重定向到另一个页面。
I want to do something like this : 我想做这样的事情:
onclick="chargement();location.href='{% url 'resumefic' upload.0.pk %}';"
but my function chargement()
isn't called, only the redirection works. 但是没有调用我的函数
chargement()
,只有重定向有效。
I can't put the location.href in a JS function as I'm using Django tags... Can someone help ? 我在使用Django标签时无法将location.href放入JS函数中。有人可以帮忙吗?
The problem is that the redirection occurs before you can see what the chargement
function has done. 问题在于重定向发生在您看到
chargement
功能完成之前。 Try adding a delay before the redirection, for example replace your code with. 尝试在重定向之前添加延迟,例如,用替换您的代码。
onclick="chargement();setTimeout(function(){location.href='{% url 'resumefic' upload.0.pk %}';},1000);"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.