【问题标题】:Is it possible to make option tag a link or button是否可以使选项标签成为链接或按钮
【发布时间】:2020-09-04 18:20:46
【问题描述】:

我正在尝试使用下拉列表中的选择来触发模态表单。在使用 django 中。

这个想法是使用是填写表格。他可以从下拉列表中进行选择,但如果他在列表中找不到所需的项目,他可以添加该项目。他将能够完成这种填充模态表单。

现在它是用按钮触发的。理想的情况是下拉列表中有按钮或链接。 像引导程序提供的东西,所谓的分离链接:

html - 下拉列表内容

<option value="">---------</option>
{% for salesPersonDistributor in salesPersonsDistributor %}
<option value="{{ salesPersonDistributor.pk }}">{{ salesPersonDistributor.name }}</option>
{% endfor %}

html - 来自模板

<form method="post" id="subsidiaryForm"  name="text" data-subsidiaries-url="{% url 'ajax_load_subsiriaies' %}" data-salesPersonsDistributor-url="{% url 'ajax_load_salesPersonsDistributor' %}" data-salesPersonsDistributorContact-url="{% url 'ajax_load_salesPersonsDistributorContact' %}" novalidate>
        <table class="table table-borderless table-condensed">
          {% csrf_token %}
          {{ form.as_table }}
        </table>
      <input type="hidden" name="build" value="{{ VCIUpdate }}">,
      <input id="submit" type="submit" value="save" />
      </form>

<div class="modal fade" tabindex="-1" role="dialog" id="modal">
    <div class="modal-dialog" role="document">
      <div class="modal-content"></div>
    </div>
  </div>
  <button id="new_sales_person_distibutor" class="btn btn-primary" type="button" name="button">Dodaj przedstawiciela</button>
</div>

jquery

 $(document).ready(function() {
            $("#new_sales_person_distibutor").modalForm({
                formURL: "{% url 'new_sales_person_distibutor' %}"
          });
   });

我曾尝试触发 jquery usung vale if 选项,但失败了。

问候 星空

【问题讨论】:

    标签: jquery django forms modal-dialog


    【解决方案1】:

    您可以将 Dropdown 与

    一起使用
    <div class="dropdown">
      <button class="btn dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        Dropdown button
      </button>
      <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
        <a class="dropdown-item" href="#">Action</a>
        <a class="dropdown-item" href="#">Another action</a>
        <a class="dropdown-item" href="#">Something else here</a>
      </div>
    </div>
    

    enter link description here

    或者用

    $('#mySelection').change(function () {
        var theChoice = $( "#mySelection option:selected" ).val()
        $( "div" ).text( theChoice ); // For explanation
        if (theChoice == "new") {
          $( "div" ).text( 'Gooooal !'); // For explanation
          // Your code here...
          }
      })
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
        <select class="custom-select" id="mySelection">
          <option selected>Open this select menu</option>
          <option value="1">One</option>
          <option value="2">Two</option>
          <option value="3">------------</option>
    <option value="new">Three</option>
        </select>
    <div></div>

    很好的延续...

    _泰迪_

    【讨论】:

    • 我使用了第二个选项。第一个在我的应用程序中不起作用。谢谢
    猜你喜欢
    • 2021-08-24
    • 2015-09-15
    • 2020-06-24
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    相关资源
    最近更新 更多