简体   繁体   English

如何刷新模式中显示的字段

[英]How to refresh fields shown in a modal

Im sure this is a very basic question, but i'm stumped! 我确定这是一个非常基本的问题,但是我很困惑! I have a modal that appears fine and what im trying to do is once a value from a dropdown is selected, have different fields appear depending on what option was picked! 我有一个看起来不错的模态,一旦从下拉列表中选择了一个值,我想做的就是根据选择的选项出现不同的字段! I know how to get the value and i intend on sending that value to a javascript method which determines what option was selected. 我知道如何获取该值,我打算将该值发送到javascript方法,该方法确定选择了哪个选项。 What i don't know is how to get different fields to appear on my modal depending on the selection. 我不知道如何根据选择使不同的字段出现在我的模态中。

Any suggestions are always appreciated! 任何建议总是感激不尽!

Edit: Here is what i'm working with 编辑:这是我正在使用的

function pickerCallback(data) {
  if (data.action == google.picker.Action.PICKED) {
    fileId = data.docs[0].id;
    $('#\\#myModal').modal('show');
    document.getElementById('doc_id').value = fileId;
    }
}

This function takes data from a picker and then the modal gets called up based on when two actions are the same. 此函数从选择器中获取数据,然后基于两个动作相同的时间调用模式。

<div id="result"></div>
<!-- The Google API Loader script. -->
<script type="text/javascript" src="https://apis.google.com/js/api.js?onload=loadPicker"></script>
    <div class="modal fade" id="#myModal">
  <div class="modal-dialog">
    <div class="modal-content">
     <div class="modal-header">
        <button type="button" class="close" onclick="createPicker()" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>

    </button>
    <h4 class="modal-title">Set Metadata</h4>
  </div>
  <div class="modal-body">
  <div id="doc_id"></div>
     Department ID: <select id = "drop" style="margin-bottom: 0.25cm;">
    <option value="#001">#001---NDA</option>
    <option value="#002">#002---Reseller Agreement</option>
    <option value="#003">#003---End User Agreement Amendments</option>
    <option value="#004">#004---Supplier Agreement</option>
    <option value="#005">#005---Third Party Providers</option>
    <option value="#006">#006---Wireless Carrier Agreements</option>
    <option value="#007">#007---Telematics Agreement Service</option>
    <option value="#008">#008---Large Customer Contract</option>
    <option value="#009">#009--Marketplace Provider Agreement</option>
  </select>

This is the modal that I was speaking about, so on the select of the option it will take the value and show different fields based on what the user has selected. 这就是我所说的模式,因此在选择选项时,它将采用值并根据用户选择的内容显示不同的字段。 I am aware that the modal is missing the ending tags there was other data in the html file below the drop down that didnt need to be touched. 我知道模态缺少结束标记,下拉菜单下方的html文件中还有其他数据不需要触摸。

Finally it will send it to a function that determines which view of the modal will be shown 最后,它将发送给一个函数,该函数确定将显示模态的哪个视图

function selectView(){
        var view = document.getElementById('drop').value;

        if (view =='NDA'){
            //show NDA view on modal
        }

    }

Thanks 谢谢

Here am adding sample HTML and am using bootstrap plugin. 在这里添加示例HTML,并在使用bootstrap插件。 In modal body we have 3 selections, based on selection content will be show/hide 在模态主体中,我们有3个选择,基于选择内容将显示/隐藏

    <div class="container">
  <h2>Activate Modal with JavaScript</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" id="myBtn">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">


        <div>
        <select>
            <option>Choose Color</option>
            <option value="red">Red</option>
            <option value="green">Green</option>
            <option value="blue">Blue</option>
        </select>
    </div>
    <div class="red box">You have selected <strong>red option</strong> so i am here</div>
    <div class="green box">You have selected <strong>green option</strong> so i am here</div>
    <div class="blue box">You have selected <strong>blue option</strong> so i am here</div>


        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</div>

And JS 和JS

$(document).ready(function(){
$("select").change(function(){
    $(this).find("option:selected").each(function(){
        if($(this).attr("value")=="red"){
            $(".box").not(".red").hide();
            $(".red").show();
        }
        else if($(this).attr("value")=="green"){
            $(".box").not(".green").hide();
            $(".green").show();
        }
        else if($(this).attr("value")=="blue"){
            $(".box").not(".blue").hide();
            $(".blue").show();
        }
        else{
            $(".box").hide();
        }
    });
}).change();

}); });

CSS would be CSS将是

    .box{
    padding: 20px;
    display: none;
    margin-top: 20px;
    border: 1px solid #000;
}
.red{ background: #ff0000; }
.green{ background: #00ff00; }
.blue{ background: #0000ff; }

DEMO FIDDLE 演示场

Please let me know is this what you required. 请让我知道这是您所需要的。

Thank you! 谢谢!

You can just hide/show the fields that you need. 您可以只隐藏/显示所需的字段。 For example: 例如:

someField.style.display = "block" //to show
someField.style.display = "none"  // to hide

Or you can add fields dynamically, like this: 或者,您可以动态添加字段,如下所示:

fieldsContainer.appendChild(someField);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在模态关闭后刷新Bootstrap模态字段 - How to Refresh the Bootstrap modal fields after modal close 如何刷新模式页面 - How to refresh page in modal BS模态-无背景,无覆盖层以及显示时能够聚焦输入字段的能力? - BS Modal - no backdrop, no overlay and ability to focus input fields when shown? 如何在模态显示之前刷新Bootstrap模态刷新 - How to refresh Bootstrap modal refresh before modal show 如何使Google Underlist以模式显示 - How to make google underlist shown in modal 通过模态实例更新字段后刷新数组的角度 - Angular to refresh array after updating fields through modal instance 如何将隐藏字段中的变量发送到远程PHP文件,并在不使用jQuery刷新的情况下在Bootstrap模式中显示脚本的结果? - How to send variables from hidden fields to a remote PHP file and display the result of the script in a Bootstrap modal without refresh using jQuery? 如何在使用show.sb.modal事件显示模态框SELECT表单控件之前对其进行填充 - How to populate a modal box SELECT form control before it is shown using the shown.sb.modal event 如何在模式关闭时刷新ng-repeat? - How to refresh ng-repeat on modal close? 如何在模态中刷新iframe的src - how to refresh a src of an iframe within a modal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM