2011-05-07 21 views
2

我認爲這會很簡單。只是Simplemodal - 如何在onShow函數中設置一個元素的焦點

... 
onShow:function(dialog){ 
    dialog.data.find("input#myInput").focus(); 
} 
... 

但它似乎沒有工作。

與SimpleModal的focus()函數有衝突嗎?

我注意到,如果我把alert()放入onShow函數中,它會在模態可見之前彈出。有沒有辦法在顯示模態後調用函數(即。focus()),但沒有用戶輸入(沒有用戶觸發某種事件)?

此外,當我試圖用simplemodal的

focus:true 

與dialog.data =

'<div class="myModal login">'+ 
    '<div class="modalTitle">Title</div>'+ 
    '<div class="modalContent">'+ 
     '<label for="username">Login: </label>'+ 
     '<input id="username" />'+ 
     '<br />'+ 
     '<label for="password">Pass: </label>'+ 
     '<input id="password" type="password" />'+ 
     '<br />'+ 
     '<div class="confirmButton no simplemodal-close">Cancel</div>'+ 
     '<div class="confirmButton yes">Login</div>'+ 
    '</div>'+ 
'</div>' 

關注的是包裝的(至少我這麼認爲)和用戶必須按標籤,即可進入第一個輸入元素。

任何幫助將是偉大的,

格雷格。

回答

1

試試這個:

onShow:function(dialog){ 
    setTimeout(function(){ 
    dialog.data.find("input#myInput").focus(); 
    },50); 
} 

希望這有助於。乾杯

+0

謝謝,我不得不把它設置爲200使它工作。你的回答是一個暗示,告訴我它爲什麼不起作用 - 我也使用onOpen函數,並帶有一些動畫。一旦我將整個onOpen函數註釋掉,即使沒有setTimeout(),它也可以工作。 – gswierczynski 2011-05-07 13:44:07

+0

我很高興幫助你。 – 2011-05-07 13:51:18

相關問題