function getRequest() {
var url = window.location.search;
var theRequest = new Object();
if (url.indexOf("?") != -1) {
?var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);?
}
}
return theRequest;
}
var username= getRequest().username;
const getParameters = (URL) => {
URL = JSON.parse(
'{"' +
decodeURI(URL.split("?")[1])
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"') +
'"}'
);
return JSON.stringify(URL);
};
getParameters(window.location);
Object.fromEntries(new URLSearchParams(window.location.search))
var options=$("#clasname option:selected");
var classname = options.text();
<select onchange="getCgfs(this);"></select>
function getCgfs(obj) {
cgfs = obj.options[obj.selectedIndex].value;
}
$("input[name='nrId']:checked").each(function(i){
let nrId = +$(this).val();
});
if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') {
}
if (['abc', 'def', 'ghi', 'jkl'].includes(x)) {
}
if (test1 !== null || test1 !== undefined || test1 !== '') {
let test2 = test1;
}
let test2 = test1 || '';
if (test1 === true) or if (test1 !== "") or if (test1 !== null)
if (test1)
switch (data) {
case 1:
test1();
break;
case 2:
test2();
break;
case 3:
test();
break;
}
var data = {
1: test1,
2: test2,
3: test
};
data[something] && data[something]();
let test1 = parseInt('123');
let test2 = parseFloat('12.3');
let test1 = +'123';
let test2 = +'12.3';
if(arr.indexOf(item) > -1) {
}
if(arr.indexOf(item) === -1) {
}
if(~arr.indexOf(item)) {
}
if(!~arr.indexOf(item)) {
}
if (arr.includes(item))
{
}
<img class="img" src="">
<input class="input-img" type="file" accept="image/*" style="display: none;">
<button class="upload-btn">选择图片上传</button>
$(".user_img_diy").click(function (){
$('.input-img').click();
});
$('.input-img').on('change', function () {
const file = $('.input-img').get(0).files[0];
if (!file || file.length === 0) {
return
}
const fileName = file.name;
const fileType = fileName.substr(fileName.lastIndexOf(".")).toUpperCase();
if (fileType !== ".GIF" && fileType !== ".PNG" && fileType !== ".JPG" && fileType !== ".JPEG") {
alert('请选择图片文件!')
return
}
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) {
alert('上传图片大小不能超过 2MB!')
$('.input-img').get(0).value = ''
return
}
const formdata = new FormData();
formdata.append("avatarfile", file);
$.ajax({
url: url,
data: formdata,
type: "post",
processData: false,
contentType: false,
success: function(result) {
console.log(result);
$('.user_img_diy').attr('src', "data:image/png;base64," +result.data)
}
})
})
* 文件流转为 base64
* @param {*} file
*/
function fileToBase64(file) {
const URL = window.URL || window.webkitURL;
return URL.createObjectURL(file);
}
var list = [{a:x,b:v}];
$.ajax({
url:'/save',
type:'post',
data:JSON.stringify(list),
contentType:"application/json",
success:function (obj)
{
},dataType:'json'
})
let chk_value = [1,2,3,4,5,6];
$.ajax({
url:'/sheet/test',
type:'post',
data:{ids:chk_value},
traditional:true,
success:function (obj)
{
},dataType:'json'
});
@Data
public class AccountVO
{
private AccountEntity accountEntity;
private List<AccountProductEntity> accountProductEntityList;
private List<AccountInvoiceEntity> accountInvoiceList;
}
function saveCommon()
{
const accountEntity = $("#kpForm").serializeJson();
const accountEntityVO = {};
accountEntityVO.accountEntity = accountEntity;
let accountProductEntityList = [];
accountProductEntitySet.forEach((el,index) => {
accountProductEntityList.push(el);
});
accountEntityVO.accountProductEntityList = accountProductEntityList;
let accountInvoiceList = [];
accountInvoiceEntityMap.forEach((el,index) => {
accountInvoiceList.push(el);
});
accountEntityVO.accountInvoiceList = accountInvoiceList;
$.ajax({
url:'/saving',
type: 'post',
data:JSON.stringify(accountEntityVO),
contentType:"application/json",
success:function (obj)
{
},dataType: 'json'
})
}
$.fn.serializeJson=function(){
var serializeObj={};
var array=this.serializeArray();
$(array).each(function(){
if(serializeObj[this.name]){
if($.isArray(serializeObj[this.name])){
serializeObj[this.name].push(this.value);
}else{
serializeObj[this.name]=[serializeObj[this.name],this.value];
}
}else{
serializeObj[this.name]=this.value;
}
});
return serializeObj;
};
@PostMapping("saving")
public AjaxResult saveAccount(@RequestBody AccountVO accountEntityVO)
{}