| 小弟新近寫了一個dynamic add table的event, 當.addow button被click時, 就會clone table最後一行, 每行格內都有一個formfield, 我在後台的JSP可以用String food[]取回值, 但我不能apply已寫好的suggestbox function到這個form field, 請問該如何處理呢? 謝謝 <script type="text/javascript">        
        $(document).ready(function() {
                $('#form1').validationEngine();
                
                var newRowNum = 0;
                $('.addRow').click(function(){
                        var $newTr = $('#tb1 tbody>tr:last').clone(true);
                        $('input[id^=foods]', $newTr).val('');
                        $newTr.insertAfter('#tb1 tbody>tr:last');
                        newRowNum += 1;                                         <==這裡想做一個counter, 想它可以識別到第newRowNum個formfield  
                        $newTr.find('input:even').attr('id', function(){
                        $('input#foods'+ newRowNum).jsonSuggest(                <==這裡想pass新產生的formfield id進去, 但不成功
                                function(text, wildCard, caseSensitive, notCharacter) { 
                                        rez = $.ajax({ 
                                        type: 'GET', 
                                        url: 'getJSON.jsp',
                                        data: 'foods=' + text,
                                        dataType: 'json', 
                                        async: false 
                                });
                                return eval(rez.responseText); 
                                },
                                { ajaxResults:true 
                                });
                        });
                });
        });
</script>已試了('#foods'+newRowNum)......等等, 都不得要領..... 但如果我直接hardcode做$('input[id=foods]').jsonSuggest( 就沒有問題, 可惜只有第一行可以出現suggestbox, 請指教, 謝謝
 [ 本帖最後由 cage 於 2009-11-11 09:57 編輯 ]
 |