我正在创建一个表单,人们可以在其中选择一个新团队,然后输入其位置,或者如果他们从列表中选择一个团队,我希望禁用输入 - 并在输入框中给出所选团队的位置. 到目前为止,这是我的代码。它不起作用。:(
<select id="chooseTeam" name="chooseTeam" data-placeholder="Select Team">
    <option></option>
    {% for team in teams %}
    <option>{{team.name}}</option>
    {% endfor %}
    <option>New Team</option>
</select>
<input type="text" id="input_location" name="input_location"/>
在一个单独的 JS 文件中:
$(document).ready(function() {
    $('#chooseTeam').on('blur', function() {
        if (form.chooseTeam.value != "New Team" && form.chooseTeam.value != "Select Team") {
            $("#input_location").html("{{team.location}}");
            document.getElementById("input_location").disabled = true;
        }
    });
});
小更新
显然,为此需要 AJAX。我是 Javascript 的新手(3 天前),所以我还不知道 AJAX 是如何工作的,但我现在正在谷歌上搜索它以试图弄清楚。
哦,祝大家圣诞快乐!
“#code-on-christmas”