creating json object with variables

后端 未结 5 1265
清歌不尽
清歌不尽 2020-12-25 13:05

I am trying to create a json object from variables that I am getting in a form.

var firstName = $(\'#firstName\').val();
var lastName  = $(\'#lastName\').va         


        
5条回答
  •  青春惊慌失措
    2020-12-25 13:41

    var formValues = {
        firstName: $('#firstName').val(),
        lastName: $('#lastName').val(),
        phone: $('#phoneNumber').val(),
        address: $('#address').val()
    };
    

    Note this will contain the values of the elements at the point in time the object literal was interpreted, not when the properties of the object are accessed. You'd need to write a getter for that.

提交回复
热议问题