2022-03-10 Work record--JS-jQuery gets the value of multiple input boxes with the same name

jQuery gets the value of multiple input boxes with the same name

$('input[name=名字]').each(function () {
  	console.log($(this).val()) ;
})

insert image description here

// 获取到所有name为sphone的input表单的输入值,并以逗号分割的字符串形式传出
var sphone = '';
$('input[name=sphone]').each(function () {
    
    
   sphone +=  $(this).val() + ',';
})
console.log(sphone.substring(0,sphone.length -1)) // 获取到以逗号分割的字符串

insert image description here

Guess you like

Origin blog.csdn.net/weixin_48850734/article/details/123404841