Change form's action attribute

前端 未结 1 1670
一生所求
一生所求 2021-01-01 03:30

Okay, I must be missing something here because this should be extremely simple, yet it doesn\'t work...

I have a form on my page with an empty act

1条回答
  •  借酒劲吻你
    2021-01-01 04:09

    It does work, you aren't testing it properly. Viewing source will show you what the source looked like when the page was loaded, not after it as modified by jQuery. If you alert() action value after it is fetched with jQuery, you will see the new value:

    alert($("#register").attr("action"));
    

    It's also generally a good idea to make sure that the DOM has loaded before you make any changes, for which you can use ready():

    $(document).ready(function(){ /* your code */ });
    

    Check out: http://jsfiddle.net/wvYjs/2/

    0 讨论(0)
提交回复
热议问题