2012-07-03 107 views
0

如果有人能幫助我,我會永遠感激。這個jQuery對話框焦點函數有什麼問題?

從本質上講,焦點函數應該是這樣的,如果用戶按下輸入任何對話框中的3個字段中的最後一個,則它充當選項卡。如果他們按下最後一欄中的輸入,它會提交表單。後面的函數可以工作,但TabB不會。

任何人都知道爲什麼?我沒有發佈整塊代碼,但是這應該提供足夠的數據。我使用event.target是否錯誤?

$('#dialog-add-items').dialog({ 
     autoOpen: false, 
     resizable: false, 
     width:500, 
     position:['center',80], 
     modal: true, 
     focus: function() { 
      $(':input:last', this).unbind('keyup').keyup(function(event) { 
       if (event.keyCode == 13) { 
        $('.ui-dialog-buttonpane button:first').click(); 
       } 
      }); 
      $(':input:not(:last)', this).unbind('keyup').keyup(function(event){ 
       if(event.keyCode == 13){ 
        name=event.target; 
        $(name).next('input').focus(); 
       } 
      }); 
     },... 

回答

0

如果我不得不猜測我會說$('.ui-dialog-buttonpane button:first').click();是罪魁禍首。試着讓你的按鈕的ID和參考這樣的:

$('#dialog-add-items').dialog({ 
     autoOpen: false, 
     resizable: false, 
     width:500, 
     position:['center',80], 
     modal: true, 
     focus: function() { 
      $(':input:last', this).unbind('keyup').keyup(function(event) { 
       if (event.keyCode == 13) { 
        $('#okbutton').click(); 
       } 
      }); 
      $(':input:not(:last)', this).unbind('keyup').keyup(function(event){ 
       if(event.keyCode == 13){ 
        name=event.target; 
        $(name).next('input').focus(); 
       } 
      }); 
     }, 
     buttons: [{text: 'Ok', id:'okbutton'}],... 
+0

沒有工作。我希望很明顯,它是第二部分不起作用,即: $(':input:not(:last)',this).unbind('keyup')。keyup(function(event){ if (event.keyCode == 13){ name = event.target; $(name).next('input')。focus(); } }); – DeltaTango

0

我只是結束了添加if/else語句,以測試其2場都集中,然後跳到下一個。煩瑣和醜陋,但這是我唯一能夠工作的事情。