我无法将所选值发送到test.html。 我写了代码
<form method="post" action="">
<select id="mainDD" data-placeholder="Choose" class="chzn-select" style="width:600px;" name="main">
{% for i in json_data.items.values %}
<option value="{{forloop.counter}}">{{ i }}</option>
{% endfor %}
</select>
{% for key, values in preprocessed %}
<select name="type" id=type{{forloop.counter}}>
{% for counter, value in values %}
<option value="{{forloop.counter}}">{{ value }}</option>
{% endfor %}
</select>
{% endfor %}
</form>
<script type="text/javascript">
$(document).ready(function () {
$('#mainDD').on('change', function() {
var thisType = "type" + $(this).val();
for(i=1; i<6; i++) {
var thisId = "type" + i;
if(thisType !== thisId) {
$("#"+thisId).hide();
}
else {
$("#"+thisId).show();
}
}
}).trigger('change');
});
</script>
<form id="postform" action="app/test_view" method="GET">
{% csrf_token %}
<input type="submit" value="SEND">
</form>
<script type="text/javascript">
var key = $('select[name="main"] option:selected').text();
var value = $('select[name="type"] option:selected').text();
var array1 = [];
var array2 =[];
document.querySelector("input[type=submit]").onclick = e => {
const test = window.open(`test_view?${key}=${value}`, "_blank");
}
</script>
我写过test.html
<h2>RESULTS</h2>
<script type="text/javascript">
onload = () => {
document.body.appendChild(
document.createTextNode([...new URLSearchParams(location.search).entries()])
);
}
</script>
我选择了i(实际值是A)&amp; index.html中的值(实际值是a-1)所以我想在test.html中显示
这2个选定的按钮加载json文件,如
{
"items":
{
"---":"---",
"A":"A",
"B":"B",
},
"type1":
{
"---":"---",
"a-1":"a-1",
"a-2":"a-2",
},
"type2":
{
"---":"---",
"b-1":"b-1",
"b-2":"b-2",
}
}
我该如何解决这个问题?我该怎么写呢?是乱码还是代码错误?