Onclick功能在Firefox中不起作用

时间:2011-05-22 06:19:33

标签: javascript firefox

function get() {

    $.post(
        'postchatfame.php', 
        {
            comment: postchatfamemsg.comment.value,
            userid: postchatfamemsg.userid.value
        },
        function(output) {
            $('#walls').html(output).show();
        }
    );

    document.forms["postchatfamemsg"].reset();

}

这是我用作Ajax的代码,用于将信息存储到DATABASE中。并以表格形式将一些信息返回到同一页面而不刷新页面。 我通过编写此代码来调用此函数onclick

<input name="a" type="button" value="Share" onClick="get();"/>

3 个答案:

答案 0 :(得分:2)

因为Fx使用标准

评论:postchatfamemsg.comment.value, 不会自己工作。它可以在IE中工作,例如因为IE使用所有可能的东西重载了作用域,这也是为什么document.getElementById('formname')将在IE中工作而不在Fx中的原因

使用comment: document.forms["postchatfamemsg"].comment.value,

完整代码

function sedData() { // get is a poor function name, especially when you post
    var form = document.forms["postchatfamemsg"];
    $.post(
        'postchatfame.php', 
        {
            comment: form.comment.value,
            userid: form.userid.value
        },
        function(output) {
            $('#walls').html(output).show();
        }
    );

    form.reset();

}

答案 1 :(得分:1)

我建议该函数使用不同的名称 - 某些名称已经在HTML和DOM中有意义,因此使用这样的名称可能会与它们发生冲突(调用函数submit也有类似的问题)。

为什么不给它一个更具描述性的名称 - 例如getChatFame

答案 2 :(得分:0)

问问自己:

  • 在尝试使用之前,您是否在代码中物理定义了函数?
  • 在您尝试使用jQuery之前,$.ajax或您正在使用的库是什么?
  • 您在JavaScript控制台中有错误吗?
  • 您能否验证该过程的任何部分是否在麻烦的浏览器中工作?
相关问题