0

我创建了代码来添加带有表单字段的表格行,并尝试将第 3 方 SuggestBox 函数绑定到每个动态生成的表单字段。

<script type="text/javascript"> 
$(document).ready(function() {
    $('#form1').validationEngine();
    var newRowNum = 1;
    $(".addRow").click(function(){
        var $newTr = $("#tb1 tbody>tr:last").clone(true);
        $newTr.find('input[id^=foods]').unbind(jsonSuggest());  <== try to unbind the previouse jsonsuggest()
        //$newTr.find('.jsonSuggestResults').remove();
        $newTr.appendTo("#tb1 tbody");
        $('input[id^=foods]', $newTr).val('');
        $newTr.find('input[id^=foods]').each(function(){
            $(this).jsonSuggest(
                    function(text, wildCard, caseSensitive, notCharacter) {
                        rez = $.ajax({ 
                            type: 'GET', 
                            url: 'getFoodJSON.jsp',
                            data: 'foods=' + text,
                            dataType: 'json', 
                            async: false 
                        });
                        return eval(rez.responseText); 
                        },
                        { ajaxResults:true 
                        });
        });
        $newTr.find('input[id^=supplyDate]').each('id', function(){
            $(this).datepicker({dateFormat:'yy-mm-dd'});
        });
    });
});

但是,SuggestBox 建议会累积重复项。这是我在第 7 行输入内容时的结果...

链接文本

您介意告诉我如何取消绑定前一行+表单字段中的应用函数吗?谢谢你。

4

1 回答 1

0

通过编写unbind(jsonSuggest()),您正在调用 jsonSuggest并取消绑定它返回的值。除非该jsonSuggest函数是返回处理程序方法的生成器(它可能不是),否则这不是您想要的。如果是,那仍然不是您想要的,除非它每次都返回相同的处理程序。

您希望(我假设)jsonSuggest通过编写unbind(jsonSuggest)不带括号来取消绑定函数本身。

于 2009-11-11T03:10:16.753 回答