如何使用组合框隐藏/显示窗体

2024-06-12 08:48:53 发布

您现在位置:Python中文网/ 问答频道 /正文

大家好:D 我不知道如何在两个可行的选择之间隐藏或显示我想要的形式。在

学生-->studentForm

员工-->employeeForm

所发生的是,虽然它改变了形式,但当我按下提交按钮,而不是选择我的组合! 但是所选组合框的名称变化很大 我不明白:3 为了达到这个目的,我交换了两个表格,即学生表格显示雇员的表格,反之亦然。。。在

如果我把值逻辑地放在那里,当学生表单出现并提交什么都没有做 我的代码是用Django python编写的

我不知道jquery或表单中的问题是什么?在

这是我的模板

<!DOCTYPE html>

{% extends "polls/base.html" %}
{% block title %}Création d'un profil{% endblock %}
{% block bodyId %}userProfilePage{% endblock %}

{% block content %}
<script type="text/javascript" src="/static/js/jquery-1.12.0.min.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        displayRightForm();
    });

    function displayRightForm() {
        if ($("#profileType").val() == 'employee') {
            $('#employeeForm').hide();
            $('#studentForm').show();
        } else {
            $('#studentForm').hide();
            $('#employeeForm').show();
        }
    }
$('select').on('change', function() {
    displayRightForm();
});
</script>


<h1>Création d'un compte</h1>
<form>
    <p>
        <label>Vous êtes :</label>
        <select id="profileType">
            <option value="student" {% if studentForm.is_bound %} selected="selected" {% endif %}>Étudiant</option>
            <option value="employee" {% if employeeForm.is_bound %} selected="selected" {% endif %}>Employé</option>
        </select>
    </p>
</form>

<form action="register" method="GET" id="employeeForm">
    {{ employeeForm.as_p }}
    {% csrf_token %}
    <p>
        <input type="hidden" name="profileType" value="employee" />
        <input type="submit" value="Créer un compte" />     
    </p>
</form>

<form action="register" method="GET" id="studentForm">
    {{ studentForm.as_p }}
    {% csrf_token %}
    <p>
        <input type="hidden" name="profileType" value="student" />
        <input type="submit" value="Créer un compte" />
    </p>
</form>

<div id="two">


<link rel="stylesheet" type="text/css" href="/static/css/style.css"/>

{% endblock %}

我试过这个方法:

^{pr2}$

但别再工作了。。。在


Tags: formidinputvaluetypescript学生表格
2条回答

这里有一个例子:

$(document).ready(function() { action(); $(".disabler").on("change", action); }); function action() { var checked = $(".disabler").prop("checked"); if (checked) { $(".showable").removeClass("hidden"); } else { $(".showable").addClass("hidden"); } } ; ^{pr2}$ ;

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

Show form
<input class="disabler" type="checkbox">

<div class="showable">
  <h2>Form</h2>
  
  <form class="form">
  Name <input type="text">
  </form>
  
</div>
和13;
和13;

请检查这个帖子

show and hide div depending upon selected checkbox with combobox option

使用表单id可以显示隐藏表单。在

相关问题 更多 >