0

只有当我在 Internet Explorer 中点击控制台时,我的表单才有效。可以在所有其他浏览器中正常工作。

这是 HTML:为什么当我打开控制台时,在 IE 中一切正常?

        <div class="clubregister">
    <h2>
        Signup Form</h2>
    <p>
        We wont give your information to anyone. It is used to notify you of promotions occasionally and required for registration.</p>
    <label for="name">Name:</label><br />
    <input name="name" type="text" /><br />
    <label for="address">Address:</label><br />
    <input name="address" type="text" /><br />
    <label for="phone">Phone:</label><br />
    <input name="phone" type="text" /><br />
    <label for="email">Email:</label><br />
    <input name="email" type="text" /><br />
    <input class="button" name="submit" style="margin-top:10px;" type="button" value="Join Club" /></div>

这是 Javascript:当调出控制台时,这一切在 IE 中的工作方式真的很奇怪。

   <script type="text/javascript">
   /////////////////////////////////////////////
   //ARRAY DUMP FUNCTION
   function dump(a,b){var c="";if(!b)b=0;var d="";for(var e=0;e<b+1;e++)d+="          ";if(typeof a=="object"){for(var f in a){var g=a[f];if(typeof g=="object"){c+=d+"'"+f+"'   ...\n";c+=dump(g,b+1)}else{c+=d+"'"+f+"' => \""+g+'"\n'}}}else{c="===>"+a+"<===("+typeof  a+")"}return c}
  /////////////////////////////////////////////
$(document).ready( function() {
    $('.clubregister  input[name="submit"]').click( function(event) {
        event.preventDefault();
                    /*alert('This section is under construction, please contact us to get set up!\n Sorry for the inconvenience');return false;*/
        //CREATE ARRAY FROM FORM DATA SERIALIZED
        var $formData = $('.clubregister input[type="text"], .clubregister textarea').serializeArray();
        //PUSH ACTION TO ARRAY
        $formData.push({'name':'action','value':'registerForClub'});
        //SEND DATA TO HANDLER
        $.ajax({
            url:'http://torkliftcentralrv.com/club_register_handle.php',
            dataType:'json',
            async:false,
            data:$formData,
            success: function(data) {
                //console.log(dump(data));
                //CREATE MESSAGE
                var message = '';
                var consolemessage = '';
                //IF ERRORS
                if(typeof data['error'] !== 'undefined') {
                    //APPEND ERRORS TO MESSAGE
                    $.each( data['error'], function( index,data) {
                        message += (data + "\n");
                    });
                }
                //IF MESSAGES
                if(typeof data['message'] !== 'undefined') {
                    //APPEND MESSAGES TO MESSAGE
                    $.each( data['message'], function( index,data) {
                        message += (data + "\n");
                    });
                }

                //IF CONSOLE MESSAGES
                if(typeof data['console'] !== 'undefined') {
                    //APPEND CONSOLE MESSAGES TO MESSAGE
                    $.each( data['console'], function( index,data) {
                        consolemessage += (data + "\n");
                    });
                }
                //IF SUCCESS SENT FROM SERVER
                if(typeof data['success'] !== 'undefined') {
                    //CLEAR FORM
                    $('.clubregister input[type="text"], .clubregister textarea').val('');
                }
                alert(message);

            }
        });
    });
});

谢谢!

4

2 回答 2

4

正如我在评论中所说,我怀疑你有一个未注释的电话到console.log某个地方。

这是 IE 上的常见问题,因为当开发人员工具未打开时,控制台对象不可用。

常见的解决方法是构建一个虚拟对象以在它不可用时替换它:

if (!window.console) {
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
    window.console = {};
    for (var i = 0; i < names.length; ++i) {
        window.console[names[i]] = function() {};
    }
}
于 2012-12-04T17:56:25.577 回答
3

Internet Explorerconsole仅在开发人员工具处于活动状态时(例如,按 F12)才公开对象。

如果开发人员工具被隐藏,那么调用console.log将引发异常,因此,javascript 代码将中断。

于 2012-12-04T17:54:22.337 回答