var d = $("#nw-dns_ip1_addr").val()+','+$("#nw-dns_ip2_addr").val();
server_ip = [d.replace(/^,|,$/,"")]; //this will remove start and end comma
alert(server_ip);
我正在获得190.82.0.56,170.20.0.20。我需要像清单中的“ 190.82.0.56”,“ 170.20.0.20”。
但是当我也有单一价值时应该处理
var d = $(“#nw-dns_ip1_addr”)。val();在这种情况下我得到'“'$(”#nw-dns_ip1_addr“)。val()'”'
“ 190.82.0.56”,“” :(
最佳答案
您需要在单引号中加上双引号。
Live Demo
var d ='"'+ $("#nw-dns_ip1_addr").val()+'","'+$("#nw-dns_ip2_addr").val() + '"';
server_ip = [d.replace(/^,|,$/,"")]; //this will remove start and end comma
alert(server_ip);
编辑单个IP地址
Live Demo
var d ='"'+ $("#nw-dns_ip1_addr").val()+'"';
server_ip = [d.replace(/^,|,$/,"")];