javascript - Django 模板中的 Javascript
问题描述
我在 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”代表缺陷。
解决方案
我认为 django 标签之外的用户 qoutes 是一个更好的主意。var pageStrucVal = parseInt('{{ pagestruc }}');
推荐阅读
- apache-spark - 如何在运行 Spark 时获取暂存目录?
- sql - 比较 SQL 中的两个关系
- javascript - 在 AJAX 调用后隐藏 jQuery 中的按钮
- solr - SOLR:fq 查询不适用于自定义字段
- elasticsearch - 关键字类型的嵌套文档的范围查询
- java - 如何防止**“java.net.ProtocolException:读取输入后无法写入输出”** Java 中的错误代码?
- android - 如何处理共享相同视图模型和实时数据的片段导致两个片段上的相同操作?
- azure - Azure Databricks 作业通知电子邮件
- javascript - 遍历 JSON 对象以映射列名和值
- android - ViewModel 类不断返回 Runtime 和 IllegalAccessException