简体   繁体   English

Twitter Bootstrap表格。 如何捕获在表单中输入的值?

[英]Twitter Bootstrap Form. How do I capture values entered in the form?

I am a Twitter Bootstrap newbie and I had to dive in to the deep end a bit. 我是Twitter Bootstrap的新手,我不得不深入研究。 I have a project where I have a form embedded in a modal. 我有一个项目,其中有一个嵌入在模态中的表单。 The form is used to pass values to a JS object. 该表单用于将值传递给JS对象。 There is no server involvement at all. 完全没有服务器参与。

The form: http://getbootstrap.com/css/?#forms 表格: http//getbootstrap.com/css/?#forms

The modal: http://getbootstrap.com/javascript/#modals 模态: http : //getbootstrap.com/javascript/#modals

I have a few questions: 我有几个问题:

  1. How and where are values captured/stored in the form when I press "submit"? 当我按“提交”时,如何以及在表格中何处捕获/存储值?
  2. How do I pass these values back to my JS object. 如何将这些值传递回我的JS对象。

Note: I have been getting up to speed on custom data attributes. 注意:我一直在加快自定义数据属性的速度。 Do they play a role here? 他们在这里发挥作用吗?

UPDATE Here is the form code I am using: 更新这是我正在使用的表单代码:

<form class="form-horizontal" role="form">

  <div class="form-group">
    <label for="inputFilterMinimum" class="col-sm-2 control-label">Minimun</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="inputFilterMinimum_TRACK_LABEL" placeholder="Minimum">
    </div>
  </div>

  <div class="form-group">
    <label for="inputFilterMaximum" class="col-sm-2 control-label">Maximum</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="inputFilterMaximum_TRACK_LABEL" placeholder="Maximum">
    </div>
  </div>

  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default">Apply</button>
    </div>
  </div>

</form>

So the idea is I want to convey the minimum and maximun values to a JS object I have implemented when I press the "Apply" button. 因此,我的想法是,当我按下“应用”按钮时,我要将最小和最大值传递给已实现的JS对象。

You can capture the variables on close of the modal and use them in anyway you want. 您可以在模态关闭时捕获变量,并以任何需要的方式使用它们。 This is using jQuery UI's dialog function: 这是使用jQuery UI的dialog函数:

$( "#MyDialog" ).dialog({
                autoOpen: false,
                height: 300,
                width: 350,
                modal: true,
                buttons: {
                    "Save": function() {
                        $('#name').val($('#firstname').val() + " " + $('#lastname').val());
                        $( this ).dialog( "close" );
                    },
                    "Cancel": function() {
                        $( this ).dialog( "close" );
                    }
                },
                close: function() {
                    //do what you want with the values here
                    $('#firstname').val("");
                    $('#lastname').val("");
                }
            });

            $( "#name" ).click(function() { $( "#MyDialog" ).dialog( "open" ); });
        });

JSFiddle Example JSFiddle示例

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM