OnClick HTML按钮:调用Javascript函数+ location.href(Django)

时间:2022-11-20 15:21:21

How can I put 2 operations in my onclick parameter, one calling a Javascript function, the other giving location.href with Django tags ? I want to make something appear on the page before redirecting to another page.

如何在我的onclick参数中放置2个操作,一个调用Javascript函数,另一个用Django标签给出location.href?我想在重定向到另一个页面之前在页面上显示一些内容。

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 ?

我不能把location.href放在JS函数中,因为我正在使用Django标签......有人可以帮忙吗?

1 个解决方案

#1


0  

The problem is that the redirection occurs before you can see what the chargement function has done. 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);"

#1


0  

The problem is that the redirection occurs before you can see what the chargement function has done. 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);"