![](/img/trans.png)
[英]How I can use a django variable in if statement of django template into a javascript string variable
[英]How can I use django template variable as an argument to call javascript function?
1.這是我調用的javascript代碼changeButton的html代碼。
<a href="#" class="btn btn-primary btn-sm" href="#" onclick="changeButton( "{{ request.session.variable }}" );return false;">Button</a>
2.這是我正在調用的javascript函數。
function changeBookNowButton(variable) {
document.getElementById("bookButton").innerHTML=variable
}
3.參數:: request.session.variable的值是:joe
我收到錯誤消息:1. SyntaxError:如果我在雙引號中使用參數“ {{request.session.variable}}”,語法錯誤2.並且如果沒有qoutes {{request.session.variable}} ReferenceError:未定義joe
嘗試這個,
<a href="#" class="btn btn-primary btn-sm" href="#" onclick="changeButton( '{{ request.session.variable }}' );return false;">Button</a>
'{{request.session.variable}}'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.