簡體   English   中英

如何在BootstrapDialog中設置對輸入元素的關注

[英]How to set focus on input element in BootstrapDialog

我有一個帶有輸入元素和其他內容的BootstrapDialog,當BootstrapDialog出現時,我需要將焦點設置在輸入元素上。

這是我的代碼:

var instanceDialogClientDonneur = null;
...
if (instanceDialogClientDonneur == null  ) {
instanceDialogClientDonneur = new BootstrapDialog.show({
        title : titre,
        cssClass : 'lieu-dialog',
        modal : true,

        closeOnEscape : true,
        onhidden : function() {             
        instanceDialogClientDonneur =null;
            },
        message : enteteZoneRecherche + resTab +"</div>"
    });
} else {
...
}

enteteZoneRecherche是這樣的:

<div class="row"><div class="input-group"><span class="input-group-addon">Rechercher</span><input type="text" id="code_recherche" value="" onkeyup="completerClient(event,this.id,'clientnom','Liste des clients','remplirZonesClientAdrEnvoi','',true);" class="form-control" placeholder="Tapez un code..."></div>

和resTab:

<div id="tableauResultat" class="row" style="height:350px;overflow-y: scroll"><table class="table table-bordered table-hover"><tr><th>Code</th><th>Nom</th><th>Ville</th></tr><tr id="idTr_1106" onclick="remplirZonesClientAdrEnvoi(this.id);"><td>000006</td><td>ARSENE</td><td>Brest</td></tr><tr id="idTr_1107" onclick="remplirZonesClientAdrEnvoi(this.id);"><td>100004</td><td>ANQUETIL</td><td>BRIVES</td></tr></table></div>

我需要將重點放在“ code_recherche”上。

我怎樣才能做到這一點 ?

官方引導程序文檔僅提供了一個示例http://getbootstrap.com/javascript/#modals

文檔中的示例

$('#myModal').on('shown.bs.modal', function () {
  $('#myInput').focus()
})

當使用BoostrapDialog類時,相同的東西看起來像

onshown: function(dialogRef){
   $('#myInput').focus();
}

因此您的最終代碼將如下所示

if (instanceDialogClientDonneur == null  ) {
    instanceDialogClientDonneur = new BootstrapDialog.show({
        title : titre,
        cssClass : 'lieu-dialog',
        modal : true,

        closeOnEscape : true,
        onhidden : function() {             
            instanceDialogClientDonneur =null;
        },
        onshown: function(){
            $('#code_recherche').focus();
        }
        message : enteteZoneRecherche + resTab +"</div>"
    });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM