簡體   English   中英

如何將新屬性添加到 <form> 使用jquery / javascript

[英]How to add new attribute to the <form> using jquery/javascript

我正在從我的queryString var中的其他文件中獲取完整的表單。現在,我想在副表單標簽中添加method =“ POST”

  var queryString = document.getElementById("render").value;

我嘗試了.attr,.append之類的可能性,但沒有起作用...

我從文件中獲取的表格samle / skalaton代碼是...

     <form class="form-horizontal">
      <fieldset>

       <!-- Form Name -->
        <legend>Form Name</legend>

      </fieldset>
     </form>

誰能告訴我該怎么做?

提前致謝

試試這個1:-

$(".form-horizontal").attr("method","post");

像這樣的東西-

queryString = queryString.replace('<form','<form method="POST" ');

.attr()方法應該可以工作。 使用此功能,您可以設置元素的任何屬性。

$(".form-horizontal").attr("method", "post");

參見http://jsfiddle.net/KCMXW/

試試這個JS(不使用jQuery庫)

document.querySelectorAll('.form-horizontal')[0].setAttribute("method","post");

演示

暫無
暫無

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

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