删除表单的动作属性

时间:2012-05-06 12:01:44

标签: jquery

如何在页面加载时删除表单的操作属性操作?

我的表单是

<form action="process" class="TTWForm ui-sortable-disabled" method="post"
      novalidate="">


           <div id="field2-container" class="field f_100 ui-resizable-disabled ui-state-disabled">
                <label for="field2">
                     Comments
                </label>
                <textarea rows="5" cols="20" name="field2" id="field2" required="required"></textarea>
           </div>


           <div id="field3-container" class="field f_100 radio-group required ui-resizable-disabled ui-state-disabled">

                <label for="field3-1">
                     Work
                </label>


                <div class="option clearfix">
                     <input name="field3" id="field3-1" value="Needs Revisions" type="radio">
                     <span class="option-title">
                          Needs Revisions
                     </span>
                </div>


                <div class="option clearfix">

                     <input name="field3" id="field3-2" value="Fine" type="radio">
                     <span class="option-title">
                          Fine
                     </span>
                </div>


                <div class="option clearfix">
                     <input name="field3" id="field3-3" value="Unstable" type="radio">
                     <span class="option-title">
                          Unstable
                     </span>

                </div>
           </div>


           <div id="form-submit" class="field f_100 clearfix submit">
                <input value="Submit" type="submit">
           </div>
      </form>

2 个答案:

答案 0 :(得分:6)

$(function(){
    $('form.TTWForm.ui-sortable-disabled').attr('action', '');
});

或者:

$(function(){
    $('form.TTWForm.ui-sortable-disabled').removeAttr('action');
});

如果您想将其值更改为foo

$(function(){
    $('form.TTWForm.ui-sortable-disabled').attr('action', 'foo');
});

答案 1 :(得分:1)

您可以选择表单,然后使用jQuery的.removeAttr()方法删除该属性。

这样的事情:

// Wait for the document to be ready
$(function(){
   // Remove the attribute from the form
   $("form.TTWForm.ui-sortable-disabled").removeAttr("action");
});