Jquery get form field value

前端 未结 8 2248
醉酒成梦
醉酒成梦 2020-12-01 07:13

I am using a jquery template to dynamically generate multiple elements on the same page. Each element looks like this

8条回答
  •  一整个雨季
    2020-12-01 07:37

    You can get any input field value by $('input[fieldAttribute=value]').val()

    here is an example

    displayValue = () => {
    
      // you can get the value by name attribute like this
      
      console.log('value of firstname : ' + $('input[name=firstName]').val());
      
      // if there is the id as lastname
      
      console.log('value of lastname by id : ' + $('#lastName').val());
      
      // get value of carType from placeholder  
      console.log('value of carType from placeholder ' + $('input[placeholder=carType]').val());
    
    }
    
    

提交回复
热议问题