var testResult
function ajax () {
return new Promise(resolve => {
$.ajax({
url: 'test.php',
method: "POST",
data: { test: 'test', },
success: data => resolve(data)
})
})
}
(async () => {
testResult = await ajax ()
console.log(testResult)
})()
найти все слова начинающиеся на t,
let matchWords = document.querySelector('p').textContent.replace(/[\.,:;-]/g, '').split(' ').filter(e => e.toLowerCase()[0] == 't').join(', ')
console.log(matchWords)
let imageParts = [0,1,2,3,4,5,6,7,8,9]
imageParts.sort((a, b) => Math.random() - 0.5 );
console.log(imageParts)
document.addEventListener('submit', function(e) {
e.preventDefault()
console.log(e.target.id)
})
по подробней?
function myChangeHandler() {
const checkedInputs = myForm.querySelectorAll('input:checked');
const ids = Array.from(checkedInputs).map(inp => inp.id);
const idsListString = JSON.stringify(ids);
(async () => {
let answer = await fetch('handler.php',{
method: 'POST',
headers: {'Content-type' : 'application/x-www-form-urlencoded; charset=UTF-8'},
body: 'arrFromJS=' + idsListString // на сервере ловить $_POST['arrFromJS']
}),
data = await answer.text();
console.log(data);
})();
// display
out.textContent = idsListString
// save
localStorage.setItem('data', idsListString)
}
let block = document.querySelectorAll('.block');
let container = document.querySelector('.container');
for(let el of block){
el.addEventListener('click',()=> {
container.setAttribute('class',`${container.classList[0]} ${el.classList[1]}`);
});
}
<div class="container"></div>
<div class="blocks">
<div class="block _black"></div>
<div class="block _blue"></div>
<div class="block _red"></div>
<div class="block _yellow"></div>
</div>
let container = document.querySelector('.container');
document.querySelector('.blocks').addEventListener('click',e => {
if(e.target.classList.contains('block')) container.className = `${container.classList[0]} ${e.target.classList[1]}`;
});
<script type='text/javascript' src='http://code.jquery.com/jquery-1.10.1.min.js'></script>
<script type='text/javascript'>
$(window).on('load', function () {
$('#wrap_preloader').delay(500).fadeToggle(500);
});
</script>
<div id='wrap_preloader'>
Идет загрузка...
</div>
#wrap_preloader {
width: 100%;
height: 100%;
position: fixed;
margin: 0px auto;
background: #282828;
z-index: 9999;
text-align: center;
color: #fff;
letter-spacing: 5px;
font-family: arial;
font-size: 50px;
padding-top: 260px;
}