function replaceString(a, b) {
const regex = new RegExp(a, 'g');
const result = b.replace(regex, '0');
return result;
}
const a = 'a++['.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&')
const b = 'Thisa++this';
const replacedString = replaceString(a, b);
console.log(replacedString);
// function makeAsyncRequest(url) {
// return new Promise((resolve, reject) => {
// // 异步请求的逻辑,例如使用fetch或XMLHttpRequest发送请求
// // 这里使用setTimeout模拟异步请求
// setTimeout(() => {
// resolve(`请求成功: ${url}`);
// }, Math.random() * 3000);
// });
// }
// function makeConcurrentRequests(urls, concurrent) {
// const results = [];
// const requests = urls.map(url => makeAsyncRequest(url));
// return new Promise((resolve, reject) => {
// let index = 0;
// function sendRequest() {
// if (index >= urls.length) {
// resolve(results);
// return;
// }
// const currentUrl = urls[index];
// const currentRequest = makeAsyncRequest(currentUrl);
// currentRequest
// .then(result => {
// results.push(result);
// })
// .catch(error => {
// console.error(`请求失败: ${currentUrl}`, error);
// })
// .finally(() => {
// index++;
// if (index < urls.length) {
// sendRequest();
// }
// });
// index++;
// }
// for (let i = 0; i < concurrent; i++) {
// sendRequest();
// }
// });
// }
// const urls = ['url1', 'url2', 'url3', 'url4', 'url5', 'url6', 'url7']; // 异步请求的URL数组
// const concurrentRequests = 3; // 并发请求数量
// makeConcurrentRequests(urls, concurrentRequests)
// .then(results => {
// console.log(results);
// })
// .catch(error => {
// console.error(error);
// });
// const add = (str1, str2) => {
// let carry = 0
// let i = str1.length - 1
// let j = str2.length - 1
// let result = ''
// while (i >= 0 || j >= 0 || carry > 0) {
// const curSum = Number(i >= 0 ? str1[i] : 0) + Number(j >= 0 ? str2[j] : 0) + carry
// const curLeft = curSum % 10
// result = curLeft + result
// carry = Math.floor(curSum / 10)
// i--
// j--
// }
// return result
// }
// const a = add('12345678901234567890', '98765432109876543210')
// console.log('aaa', a)
// const btn = document.querySelector('.btn')
// btn.addEventListener('click', () => {
// const a = performance.getEntries()
// // const a = performance.getEntriesByName('largest-contentful-paint');
// console.log('aa', a);
// new PerformanceObserver((entryList) => {
// const entries = entryList.getEntries();
// const entry = entries[entries.length - 1];
// console.log('lcp', entry, entries);
// }).observe({ type: 'largest-contentful-paint', buffered: true });
// // const form = new FormData()
// // form.append('a', 2)
// // // window.location.replace('https://www.baidu.com/s?ie=UTF-8&wd=%E5%8D%95%E9%A1%B5%E5%BA%94%E7%94%A8%E7%9A%84sendBeaconm')
// // navigator.sendBeacon('/aaa', form)
// })
// setTimeout(() => {
// window.location.replace('https://www.baidu.com/s?ie=UTF-8&wd=%E5%8D%95%E9%A1%B5%E5%BA%94%E7%94%A8%E7%9A%84sendBeaconm')
// navigator.sendBeacon('/aaa')
// }, 3000)
<div class="con">
<div class="btn">aa</div>
<!-- <div class="btn2">bb</div> -->
</div>
.con {
width: 200px;
height: 200px;
background: grey;
position: relative;
overflow: auto;
}
.btn1 {
/* background: red; */
height: 1500px;
border: 50px solid yellow;
position: absolute;
left: 0;
top: 0;
right: 0;
z-index: 1;
}
/* .btn2 {
/* background: red; */
height: 190px;
border: 5px solid yellow;
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 2;
} */