0

私はこのコードを持っています

<script>
function cA( url )
{
    document.myform.action = url;
}
</script>

<input type="whatever" name="whatever" id="whatever" />                        
<button class="whatever-button" id="defaultAction" value="Go for it" name="whatever" type="submit" onClick="cA('whatever.php#anchor')" >Go for it                                                                                             
</button>  

Go for it-Button をクリックすると、whatever.php#anchorロードされます。cA('whatever.php#anchor')ボタンのクリックと同じように実行するには、入力タグの要素をどのように変更する必要がありますか?

そのため、ユーザーがフィールドで Enter キーを押すと、サイトwhatever.php#anchorが読み込まれるか、具体的にcA('whatever.php#anchor')は実行されます。

ページには複数のボタンがあるため、1 つのボタンをデフォルト ボタンにすると機能しません。

PS:

ページの構造が

<form>
    <script>
    function cA( url )
    {
        document.myform.action = url;
    }
    </script>

    <input type="whatever1" name="whatever1" id="whatever1" />                        
    <button class="whatever1-button" id="defaultAction1" value="Go for it" name="whatever1" type="submit" onClick="cA('whatever.php#anchor1')" >Go for it                                                                                             
    </button> 

    <input type="whatever2" name="whatever2" id="whatever2" />                        
    <button class="whatever2-button2" id="defaultAction2" value="Go for it" name="whatever2" type="submit" onClick="cA('whatever.php#anchor2')" >Go for it                                                                                             
    </button> 

    <input type="whatever3" name="whatever3" id="whatever3" />                        
    <button class="whatever3-button" id="defaultAction3" value="Go for it" name="whatever3" type="submit" onClick="cA('whatever.php#anchor3')" >Go for it                                                                                             
    </button> 
    ...        
</form>    
4

1 に答える 1