我是 Twitter Bootstrap 新手,我必须深入了解一下。我有一个项目,其中有一个嵌入模式的表单。该表单用于将值传递给 JS 对象。根本不涉及服务器。
形式: http://getbootstrap.com/css/?#forms
模态: http://getbootstrap.com/javascript/#modals
我有几个问题:
- 当我按“提交”时,表单中的值如何以及在何处被捕获/存储?
- 如何将这些值传递回我的 JS 对象。
注意: 我一直在加快了解自定义数据属性。他们在这里发挥作用吗?
更新 这是我正在使用的表单代码:
<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>
所以我的想法是,当我按下“Apply”按钮时,我想将最小值和最大值传递给我已实现的 JS 对象。
最佳答案
您可以在模式关闭时捕获变量并按照您想要的方式使用它们。这是使用 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" ); });
});
关于javascript - Twitter Bootstrap 表单。如何捕获表单中输入的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24195865/