2016-09-11 3 views
1

JavaScriptを使用してアクションフィールドのテキストに新しい値を割り当てる方法はありますか?JavaScriptのアクションフィールドの参照

<form name="submitForm" action="THIS_TEXT"> 
    <input type="submit" class="button">See Results</input> 
</form> 

ありがとうございます。

答えて

1

あなたはあなたのform名前document.forms["submitForm"]によって、あなたがしたい属性に新しいテキストを設定するsetAttribute()機能を使用して参照することができます:

document.forms["submitForm"].setAttribute("action", "new_text_here"); 

注:その後input自己終了タグです、 inputボタンは次のようになります。

<input type="submit" class="button" value="See Result"/> 

これが役立つことを願っています。

document.forms["submitForm"].setAttribute("action", "new_text_here"); //set action 
 

 
console.log(document.forms["submitForm"].getAttribute("action")); //get action
<form name="submitForm" action="THIS_TEXT"> 
 
    <input type="submit" class="button" value="See Result"/> 
 
</form>

0

これだけ名前submitFormとの一つの形を持っていると仮定。ページに複数のフォームがある場合は、それらにIDを与え、document.getElementByIdを代わりに使用する必要があります。

$forms = document.getElementsByName("submitForm"); 
 
$form = $forms[0]; 
 

 
$form.setAttribute("action", "NEW ACTION");
<form name="submitForm" action="THIS_TEXT"> 
 
    <input type="submit" class="button">See Results</input> 
 
</form>

0

また、このような方法で試みることができます。

<form name="submitForm" action="THIS_TEXT"> <input type="submit" class="button">See Results</input> </form>

そして今、Javascriptを

$('form[name="submitForm"]').attr('action','revised_action_url'); 
+0

ように注意してください、OPにはjQueryのタグはありません。 –

関連する問題