簡體   English   中英

(javascript)onClick =“form.submit();不適用於IE和Opera

[英](javascript) onClick="form.submit(); doesn't work on IE & Opera

我有一個代碼(見下文)。 它在Firefox中完美運行:它在單擊__JL_SAVE按鈕后保存提交的信息並使用戶保持在同一頁面上。 但是在Internet Explorer和Opera中它只重定向到索引頁面(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

您應該在FORM的“提交”事件處理程序中執行任何與提交相關的邏輯,而不是在“FORM”元素之一的“單擊”中執行。 例如:

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

這應確保基於鍵盤的提交通過您的處理程序; 它還使您能夠通過從事件處理程序返回falsy值來阻止表單提交。 另一方面,任何真實的價值都會自動提交一份表格。

  1. 如果您沒有更改表單的行為,為什么要使用JavaScript來提交表單?,您已經在提交按鈕中。

  2. 您應該嘗試使用表單name =“mosForm”,而不僅僅是id =“mosForm”,以便可以找到該事件處理程序的DOM引用。

當你有:

<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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM