(javascript)onClick =“form.submit();不适用于IE和Opera

时间:2009-08-20 03:11:54

标签: javascript internet-explorer firefox

我有一个代码(见下文)。它在Firefox中完美运行:它在单击 __ JL_SAVE 按钮后保存提交的信息,并使用户保持在同一页面上。 但在Internet Explorer&它只会重定向到索引页面(index.php)并且不保存提交的信息。 我该怎么做才能解决这个问题?感谢。

这是我的代码:

<form action="index.php" id="mosForm" method="post" enctype="multipart/form-data">

    <fieldset>
        <legend><?=__JL_ABOUT_MYSELF?></legend>
        <span class="a" onclick="showHideLegend('about_myself_1')"><?=__JL_EDIT_BLOCK;?></span>
        <div id="about_myself_descr" style="display: block"><?=__JL_SELF_DESCR;?></div>
        <div id="about_myself_1" style="display: none"><?php include "html/about_myself_fill.php"?></div>
        <div id="about_myself_2""><?php include "html/about_myself_show.php"?></div>
    </fieldset>

    <fieldset>
        <legend><?=__JL_ABOUT_MYSELF?></legend>
        <span class="a" onclick="showHideLegend('type_1')"><?=__JL_EDIT_BLOCK;?></span>
        <?php if ($typ_block) {?>
            <?php /* <input type="checkbox" id="jl_type_block" name="jl_type_block" <?php if ($roon_type_block) echo 'checked ';?> /> */ ?>
            <input type="checkbox" id="jl_type_block" name="jl_type_block" disabled <?php  echo 'checked ';?> />
            <label for="jl_type_block"><?=__JL_ON_BLOCK?></label>
        <?php } else {
            echo __JL_OFF_BLOCK;
        }?>

        <div id="about_myself_descr" style="display: block"><?=__JL_SELF_DESCR;?></div>

        <div id="type_1" style="display : none">
            <?php include "html/type.php"?>
        </div>
        <?php if ($typ_block) { ?>
            <div id="type_2">
                <?php include "html/type_show.php"?>
            </div>
        <?php } ?>
        </fieldset>

        <fieldset>
            <legend><?=__JL_INTEREST?></legend>
            <span class="a" onclick="showHideLegend('interest_1')"><?=__JL_EDIT_BLOCK;?></span>
            <?php if ($interest_block) {?>
                <input type="checkbox" id="jl_interest_block" name="jl_interest_block" disabled <?php echo 'checked ';?> />
                <label for="jl_interest_block"><?=__JL_ON_BLOCK?></label>
            <?php } else
                echo __JL_OFF_BLOCK;
            ?>
            <div id="interest_descr" style="display:block"><?=__JL_INTEREST_DESCR;?></div>
            <div id="interest_1" style="display:none">
                <?php include "html/interest.php"?>
            </div>
            <?php if ($interest_block) { ?>
                <div id="interest_2">
                <?php include "html/interest_show.php"?>
                </div>
            <?php } ?>
        </fieldset>


            <input type="submit" name="save" value="__JL_SAVE" onClick="mosForm.submit();" />
            <input type="hidden" name="option" value="com_joomlove" />
            <input type="hidden" id="task" name="task" value="save_info" />
            </form>

此处提供完整资源:http://narkoz.pastebin.com/f4f036f5

3 个答案:

答案 0 :(得分:10)

您应该在FORM的“提交”事件处理程序中执行任何与提交相关的逻辑,而不是在“FORM”元素之一的“单击”中执行。 e.g:

<form ... onsubmit="return validateForm(this);"> ... </form>

这应确保基于键盘的提交通过您的处理程序;它还使您能够通过从事件处理程序返回falsy值来阻止表单提交。另一方面,任何真实的价值都会自动提交一份表格。

答案 1 :(得分:8)

  1. 如果您没有更改表单的行为,为什么要使用JavaScript提交表单?,您已经在提交按钮中。

  2. 您应该尝试使用表单name =“mosForm”,而不仅仅是id =“mosForm”,以便可以找到该事件处理程序的DOM引用。

答案 2 :(得分:1)

当你有:

<form method="post" action="somefile.php" name="form" id="form">
<button type="button" name="submit" onclick="$('#form').submit()">go</button>
</form>

适用于IE8,Opera,Chrome,但不适用于Firefox(14):

Firefox遇到问题:name="submit"。当您更改name(或其他内容)中的name="submit_ff"属性时,它也适用于Firefox。

相关问题