Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript event.preventDefault();停止在FF工作_Javascript_Php_Jquery - Fatal编程技术网

Javascript event.preventDefault();停止在FF工作

Javascript event.preventDefault();停止在FF工作,javascript,php,jquery,Javascript,Php,Jquery,我有下面的代码,它到目前为止工作正常,event.preventDefault();在FireFox中似乎不会触发?在Chrome中,代码仍然可以正常工作,但在Firefox中,它会让我进入空白页面,我会看到生成的代码 $("#generate_code").click(function(){ event.preventDefault(); $('#code').html('Generating Code..'); hideshow('lo

我有下面的代码,它到目前为止工作正常,event.preventDefault();在FireFox中似乎不会触发?在Chrome中,代码仍然可以正常工作,但在Firefox中,它会让我进入空白页面,我会看到生成的代码

    $("#generate_code").click(function(){
        event.preventDefault();
        $('#code').html('Generating Code..');
        hideshow('loading',1);
        setTimeout(function() {
            $.get("generate-code.php", function(data) {
                $("#code").html(data);
            });
            hideshow('loading',0);
        }, 2000);
   });
generate-code.php:

function generateRandomString($length = 50) {
    $characters = '!@#$%^&*()0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomString;
}

$invitecode = generateRandomString();
echo $invitecode;
function generateRandomString($length=50){
$characters='!@#$%^&*()0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZABDEFGHIJKLMNOPQRSTUVXYZ';
$randomString='';
对于($i=0;$i<$length;$i++){
$randomString.=$characters[rand(0,strlen($characters)-1)];
}
返回$randomString;
}
$inviterCode=generateRandomString();
回显代码;

您应该对作为参数传递给处理程序的事件对象调用
preventDefault
,以确保所有操作都可以跨浏览器运行

$("#generate_code").click(function(e){
    e.preventDefault();
    ...

PHP代码在这里是不相关的,肯定会有人请求它,所以我只是把它放上去:)可能重复相同的结果,Chrome OK,Firefox遵循链接抱歉,使用
$(“#生成_代码”)。单击(函数(事件)
work@MariusProllak从技术上讲,参数变量的名称无关紧要。你确定你以前在这两个位置都是
e