[英]Javascript inside Django Template
我在 Django 模板中使用 JS,但 JS 代码没有响应。 该怎么办?
这在<script>
标签内:
var pageStrucVal = {{ pagestruc }};
if (pageStrucVal >= 82){
var pageWarn = ["Brilliant, your site's structure and design is awesome and rocking. <gold>RockingStructure</gold>", 'pp']
}
else if ( pageStrucVal >= 72){
var pageWarn = ["Nice, your site's structure and design is suitable", 'pp']
}
else if ( pageStrucVal < 45){
pageWarn = ["Extremely bad condition, your site's structure and design is extremely bad and unmanaged. Strictly to use a different theme or change the interface (UI). <red>#ExtremelyBad</red>", 'dd'];
}
else if ( pageStrucVal < 50){
pageWarn = ["Worst conditon, the content quality of your site is too much poor. Use a well-managed theme or change the interface (UI).<orange>#ReallyPoor</orange>", 'dd'];
}
else if ( pageStrucVal < 55){
pageWarn = ["Too much bad, your site's structure and design is too much bad and unmanaged. Try to use a different theme or change the interface (UI).<orange>#VeryPoor", 'dd'];
}
else if ( pageStrucVal < 63){
pageWarn = ["Very bad, your site's structure and design is very unmanaged. You can try to use a different theme or change the interface (UI).<orange>#MuchBad</orange>", 'dd'];
}
else if ( pageStrucVal < 72){
pageWarn = ["Bad, your site's structure and design isn't suitable. Small change in the interface (UI) is required.<green> #TendsToBad</green>", 'dd'];
}
console.log(pageWarn);
document.getElementById(pageWarn[1]).appendChild(document.createElement('p')).innerHTML = (pageWarn[0]);
是document.getElementById(pageWarn[1]).appendChild(document.createElement('p')).innerHTML = (pageWarn[0]);
正确书写并处于正确位置?
这是 HTML:
<div class='plusNdefects' id='moredetails'>
<h1>Good Aspects and Plus Points.</h1>
<p class='details'>Here are some awesome good aspects and benefits you have in your site to get Google Adsense.</p>
<!-- Ads ::> -->
{% include "ads/outads.html" %}
<!-- Ads <:: -->
<div class='persona'>
<div id='pp'> </div>
</div>
</div>
<div class='plusNdefects'>
<h1>Disabilities and Improvements.</h1>
<p class='details'>These are some disabilities of your website that are stopping you from being approved by Google
Adsense.</p>
<!-- Ads ::> -->
{% include "ads/outads.html" %}
<!-- Ads <:: -->
<div class='persona'>
<div id='dd'></div>
</div>
'pp' 和 'dd' 是我想插入消息的 id(位置)。 “pp”代表加分点,“dd”代表缺陷。
尝试var pageStrucVal = parseInt({{ pagestruc }})
;
我认为 django 标签之外的用户 qoutes 是一个更好的主意。 var pageStrucVal = parseInt('{{ pagestruc }}');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.