我的代碼出現錯誤,我使用bootstrap v3.3和jquery默認從引導,角度v1.4和指令dirPagination進行表分頁。 我使用模態引導,將模態上的輸入字段的某些值傳遞給父頁面上的輸入字段。這是我的代碼:從引導模態獲得參數到輸入字段
的.js
$(function() {
$('#listUser').on('click', '.pilih', function(e) {
var samaccountname = $('#samaccountname_modal').val(); //pass from here
//var question = $('#question_modal').val(); //pass from here
$('#samaccountname_input').val(samaccountname); //to here
//$('#question_input').val(question); //to here
$('#listUser').modal('hide'); //close modal
//console.log(samaccountname);
//console.log(question);
});
});
我的HTML輸入字段
<div class="input-group col-md-11">
<span class="input-group-addon">
<button type="button" class="btn btn-info btn-sm pull-right" data-target="#listUser" data-toggle="modal"><i class="material-icons">face</i></button>
</span>
<div class="form-group is-empty"><!-- id=samaccountname get value from modal -->
<input type="text" name="samaccountname" id="samaccountname_input" class="form-control" placeholder="click blue button for search.." readonly required />
<span class="material-input"></span>
<span id="result" />
</div>
那麼我的模態
<!-- Modal Add --><div class="modal fade" id="listUser" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body" ng-controller="ctrlList">
<form class="form">
<div class="col-md-12">
<div class="input-group">
<span class="input-group-addon">
<i class="material-icons">search</i>
</span>
<div class="form-group is-empty">
<input autofocus type="text" class="form-control" ng-model="search" placeholder="Type text here.." />
<span class="material-input"></span>
</div>
</div>
</div>
</form>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr style="font-size:12px;">
<th style="text-align: center;">No</th>
<th style="text-align: center;" ng-click="sort('nik')">NIK
<span class="glyphicon sort-icon" ng-show="sortKey=='nik'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th style="text-align: center;" ng-click="sort('nama_karyawan')">Nama Karyawan
<span class="glyphicon sort-icon" ng-show="sortKey=='nama_karyawan'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th style="text-align: center;" ng-click="sort('jabatan')">Jabatan
<span class="glyphicon sort-icon" ng-show="sortKey=='jabatan'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th style="text-align: center;" ng-click="sort('department')">Department
<span class="glyphicon sort-icon" ng-show="sortKey=='department'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th>Pilih</th>
</tr>
</thead>
<tbody>
<tr dir-paginate="adb in dataTable | orderBy:sortKey:reverse | filter:search | itemsPerPage: pageSize" pagination-id="listuserldap" style="font-size: 11px;">
<td>{{ $index+1 }}</td>
<td>{{ adb.nik }}</td>
<td>{{ adb.nama_karyawan }}</td>
<td>{{ adb.jabatan }}</td>
<td>{{ adb.department }}</td>
<td><!-- here my button pass to input value -->
<input class="btn btn-xs pilih"
type="button" value="{{ adb.nik }} , {{ adb.nama_karyawan }}"
id="samaccountname_modal" />
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<div ng-controller="ctrlPagination">
<div class="text-center">
<dir-pagination-controls pagination-id="listuserldap" boundary-links="true" on-page-change="pageChangeHandler(newPageNumber)" template-url="<?php echo Config::get('URL'); ?>pagination"></dir-pagination-controls>
</div>
</div>
</div>
</div>
</div>
,並導致 mymodal
和我的問題 如果我點擊以外的表模態1號,父菜單上的值輸入字段每次總是從沒有1路過,請給我一些解決方案,請 感謝
ikwijaya
使用VAR SAM帳戶= $(此).VAL();而不是var samaccountname = $('#samaccountname_modal')。val(); – JYoThI