Build URL from form fields with JavaScript or jQuery

后端 未结 3 997
时光取名叫无心
时光取名叫无心 2021-02-07 06:22

I\'m trying to create a URL builder form with JavaScript or jQuery.

Basically, it will take the value of the two form fields, add them to a preset URL and show it on a th

3条回答
  •  忘了有多久
    2021-02-07 06:52

    jQuery has serialize which builds the query string values.

    So if you want to do the entire form:

    alert($("#form1").serialize());
    

    If you want to do only a few fields, then just make the selector select those fields.

    alert($("#variable1, #variable2").serialize());
    

提交回复
热议问题