【发布时间】:2021-12-20 14:11:01
【问题描述】:
我有一个网络应用,后端使用 Django,前端使用 HTML5。
我想将一个变量从引导表传递给 javascript 中的引用。
<th class ='Format_issued' data-field="book.publisher" data-formatter="renderFormat">Material Format</th>
<script>
function renderFormat(value) {
return '<select style="width: 7em" name="Material_format" id="Material_format" >\n' +
' <option value="">--Select--</option>\n' +
' <option value="eText" {% if ' + value + ' == "eText" %} selected="selected" {% endif %}>eText</option>\n' +
' <option value="No Material" {% if value == "No Material" %} selected="selected" {% endif %}>No Material</option>\n' +
'
' </select>'
}
</script>
'value' 是我要传递的变量。
但我尝试了几种方法:
1.使用'+值+':' <option value="eText" {% if ' + value + ' == "eText" %} selected="selected" {% endif %}>eText</option>\n'
2 。直接在我的js引用中使用值:'<option value="No Material" {% if value == "No Material" %} selected="selected" {% endif %}>No Material</option>\n'
all 无法传递 value 变量。
我如何传递“价值”?
【问题讨论】:
标签: javascript django