1

你有一个带有输入数据的表格。像

<form id = 'myform'>
...
            <td><input type="checkbox" name="supplier_aid" value="on" checked disabled >{$output.t_artikelnr}</td>
            <td><input type="checkbox" name="descshort" value="on">{$output.t_kurztext}</td>
            <td><input type="checkbox" name="buyer_aid" value="on">{$output.t_sap_materialnr}</td>
...
</form>

在准备好文档时,我用我的函数替换了默认的提交函数(唯一的方法,遗留代码再次出现......)

document.myform.submit = function (){
 //do some stuff..

//and eventually

return true;
}

但现在没有表单提交发生......谁知道我怎样才能恢复提交行为?

这是整个js

<script type="text/javascript">
       $(document).ready(function(){


        document.articlelistform.progress = {};     
        document.articlelistform.progress.update = function(){
            var variables = document.articlelistform.progress;
            var state = variables.data.done / variables.data.togo;    
            if(document.articlelistform.progress.lock){
                 variables.bar.updateProgress(state,'{/literal}{$output.m_queue_progress_message_status}{literal}')
                 return;
            }


            if(typeof(variables.togo) =='undefined'){
                variables.togo = 5;
                }
            switch(variables.data.state){
                case 'inQue':

                        variables.bar.updateProgress((5 - variables.togo) / 5,'{/literal}{$output.m_queue_progress_message_gathering}{literal}');   
                        variables.togo--;
                        if(variables.togo <= 0) variables.togo = 5;
                        document.articlelistform.submit(variables.data);

                    break;
                case 'inProcess':
                    if(variables.togo <= 0 || variables.data.update){
                        variables.togo = 5;
                        variables.bar.updateProgress(state,'{/literal}{$output.m_queue_progress_message_genarating}{literal} '+ variables.data.done + '/' + variables.data.togo);   
                        document.articlelistform.submit(variables.data);

                    }else variables.togo--;

                    break;
                case 'downloadDone': 
                        variables.bar.updateProgress(1,'{/literal}{$output.m_queue_progress_message_download}{literal}!');   
                            if(window.location != 'failed'){
                                window.location = variables.data.location;
                                clearInterval(variables.ticking);
                                delete variables.ticking;
                                variables.togo = 5;
                                variables.state = 'new';
                            }else{
                                document.articlelistform.progress.bar.updateProgress(1,'{/literal}{$output.m_queue_progress_message_networkerr}{literal}!');
                            }
                       break;
                 case 'error' :
                     clearInterval(variables.ticking);
                     delete variables.ticking;
                     variables.togo = 5;
                     variables.state = 'error';
                     document.articlelistform.progress.bar.updateProgress(1,'{/literal}{$output.m_queue_progress_message_server_error}{literal}');
                     document.articlelistform.submit(variables.data);
                     break;

            }
        }

        document.articlelistform.submit = function(data){
            var settings = document.articlelistform.progress;
            settings.lock  = true;

            if(typeof(data) == 'undefined') data = {state:'new'};

            if(typeof(settings.data) != 'undefined')
            if(settings.data.state == 'downloadDone'){
               window.location = settings.data.location; 
               return false;
            }
            if(typeof(data) == 'object')
                if(data.state == 'error') document.articlelistform.submit()

            $('#formSettings').val(JSON.stringify(data));       
            $.ajax({
                type: "POST",
                url: 'ajax-backend/downloadCatalogueProgress.php',
                data:   $(this).serialize() ,

                success: function(data){

                    settings.lock  = false;
                    if(!data.error){

                        if((data.state == 'inQue' && typeof(settings.bar) == 'undefined')||data.progress){
                            delete data.progress;
                            $('#catalogMessageHolder').html('');
                            settings.bar = new Ext.ProgressBar({
                                renderTo: 'catalogMessageHolder',
                                value: 0.1,
                                width: 200,
                                maxValue:60,
                                minValue: 0,
                                text : '{/literal}{$output.m_queue_progress_message_genarating}{literal}.'

                            });
                            settings.data  = data;     
                            document.articlelistform.progress.ticking  = setInterval(settings.update, 1000, data, true);
                        }else{
                            settings.data  = data;
                        }
                        $('#cataloLoaderHolder').show();

                    }else{
                    //@todo: implement a warning message
                    }

                },
                failure: function(){
                 document.articlelistform.progress.bar.updateProgress(1,'{/literal}{$output.m_queue_progress_message_networkerr}{literal}!');
                } 
            });

            return true; 
        };
    });

    </script>
4

3 回答 3

1

我设法从我的主管那里得到了改变该死的东西的许可。

我明白他为什么要我改变它......它在大约 20 个地方被硬编码......改变了一切。刚刚用 jquery 调用更改了 js 调用,一切正常。不知道为什么它更早起作用。但这是调用该函数的点击

> <td class="blue" background="gfx/buttonb.gif" align="center"
> valign="center"><nobr><a  href="javascript:void(0)" class="blue"
> onclick="if (!(document.articlelistform.catalogpartner3200.checked ||
> document.articlelistform.catalogpartner3582.checked ||
> document.articlelistform.catalogpartner5320.checked ||
> document.articlelistform.catalogpartner5109.checked ||
> document.articlelistform.catalogpartner4774.checked ||
> document.articlelistform.catalogpartner3271.checked ||
> document.articlelistform.catalogpartner3526.checked ||
> document.articlelistform.catalogpartner5544.checked ||
> document.articlelistform.catalogpartner3494.checked ||
> document.articlelistform.catalogpartner3416.checked ||
> document.articlelistform.catalogpartner4439.checked ||
> document.articlelistform.catalogpartner5328.checked ||
> document.articlelistform.catalogpartner5329.checked ||
> document.articlelistform.catalogpartner3267.checked ||
> document.articlelistform.catalogpartner3512.checked ||
> document.articlelistform.catalogpartner2848.checked ||
> document.articlelistform.catalogpartner3417.checked ||
> document.articlelistform.catalogpartner3491.checked ||
> document.articlelistform.catalogpartner3492.checked ||
> document.articlelistform.catalogpartner5554.checked ||
> document.articlelistform.catalogpartner5591.checked ||
> document.articlelistform.catalogpartner5611.checked ||
> document.articlelistform.catalogpartner3517.checked ||
> document.articlelistform.catalogpartner5305.checked ||
> document.articlelistform.catalogpartner3532.checked ||
> document.articlelistform.catalogpartner5077.checked ||
> document.articlelistform.catalogpartner3581.checked ||
> document.articlelistform.catalogpartner3507.checked ||
> document.articlelistform.catalogpartner3579.checked ||
> document.articlelistform.catalogpartner3489.checked ||
> document.articlelistform.catalogpartner3490.checked ||
> document.articlelistform.catalogpartner5306.checked ||
> document.articlelistform.catalogpartner5598.checked ||
> document.articlelistform.catalogpartner5191.checked ||
> document.articlelistform.catalogpartner3305.checked ||
> document.articlelistform.catalogpartner3578.checked ||
> document.articlelistform.catalogpartner3580.checked ||
> document.articlelistform.catalogpartner4934.checked ||
> document.articlelistform.catalogpartner4437.checked ||
> document.articlelistform.catalogpartner3568.checked ||
> document.articlelistform.catalogpartner4079.checked ||
> document.articlelistform.catalogpartner3723.checked ||
> document.articlelistform.catalogpartner5321.checked ||
> document.articlelistform.catalogpartner3569.checked)) {alert('Sie
> müssen mind. 1 Katalog auswählen');  } else { if
> (!(document.articlelistform.supplier_aid.checked ||
> document.articlelistform.descshort.checked ||
> document.articlelistform.buyer_aid.checked ||
> document.articlelistform.desclong.checked ||
> document.articlelistform.keywords.checked ||
> document.articlelistform.manufacturer_name.checked ||
> document.articlelistform.delivery_time.checked ||
> document.articlelistform.remarks.checked ||
> document.articlelistform.reference_feature_group_id.checked ||
> document.articlelistform.order_unit.checked ||
> document.articlelistform.content_unit.checked ||
> document.articlelistform.quantity_min.checked ||
> document.articlelistform.quantity_interval.checked ||
> document.articlelistform.price_amount.checked ||
> document.articlelistform.special_treatment_class.checked ||
> document.articlelistform.mimeinfo.checked ||
> document.articlelistform.sicherheitsdatenblatt.checked )) {alert('Sie
> müssen mind. 1 Auswahlkriterium wählen!');  } else {
> $('#catalogDownloadForm').submit(); } } return false;" onMouseOver=
> "window.status='Als CSV-Datei downloaden'; return true;"
> onMouseOut="window.status=''; return true;">&nbsp;Als CSV-Datei
> downloaden&nbsp;</a></td>

代码很疯狂....我只是从document.articlelistform.submit()to 更改为$('#catalogDownloadForm').submit()所有工作都按应有的方式工作..不知道为什么会失败。

于 2013-01-21T14:54:08.873 回答
0
document.myform.submit = function (event) {
    // init event if undefined
    if (!event) var event = window.event;
    if (doNotSubmit) {
        event.preventDefault();
        // form won't be submitted
    } else {
        // will automatically submit, no need to return anything
    }
}

编辑

显然,您使用的是 jQuery。然后,另一种解决方案可能会起作用:

$("#myForm").on("submit", function() {
    if (doNotSubmit) {
        return false;
        // form won't be submitted
    } else {
        return true;
        // form will be submitted
    }
});
于 2013-01-21T09:47:03.140 回答
0

你还没有声明一个 onsubmit 事件处理程序,你已经重新声明了提交本身!!!

所以,你真的想做:

document.myform.onsubmit = function(){
  // do some stuff...
  // and eventually
  return true;
};

看起来你做了,否则就不需要返回任何东西,因为document.myform.submit没有。

如果这是故意的(eek!),在重新定义之前,document.myform.submit您需要存储它:

document.myform.originalSubmit = document.myform.submit;
document.myform.submit = function (){
  //do some stuff..
  //and eventually
  document.myform.originalSubmit();
};

由于这会绕过您与表单关联的任何事件处理程序,因此我看不出这是您真正想要的,因为它不会与其他代码很好地配合使用。

于 2013-01-21T09:56:03.967 回答