[英]How can set jinja variable in javascript function?
function show_modal(val1, val2){
{% set msg1 = val1 %}
{% set msg2 = val2 %}
document.getElementById('id01').style.display='block'
}
I have calling show_modal()
function in some where in the template.我在模板的某些地方调用
show_modal()
function。
Needs each time assigning situational values to msg1
and msg2
每次都需要为
msg1
和msg2
分配情境值
Not working.不工作。 Each not working below:
以下每个都不起作用:
function show_modal(){
{% set msg1 = "Delete Column" %}
{% set msg2 = "Are you sure you want to delete this column?" %}
document.getElementById('id01').style.display='block'
}
May I show different prompts with this part of code?我可以用这部分代码显示不同的提示吗? (Which is invisible by default)
(默认情况下是不可见的)
<div id="id01" class="modal">
<h1>{{ msg1 }}</h1>
<p>{{ msg2 }}</p>
</div>
You have to use pure js for this, try something like this:你必须为此使用纯 js,尝试这样的事情:
function show_modal(){
let msg1 = "Delete Column";
let msg2 = "Are you sure you want to delete this column?";
document.getElementById("id01").innerHTML=`
<h1>${msg1}</h1>
<p>${msg2}</p>`;
document.getElementById('id01').style.display='block'
}
<div id="id01" class="modal">
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.