var dogs = {
Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle"
};
var myDog = "Hunter";
var myBreed = dogs[myDog];
var myBreed = myDog;
text[1] = '<b class="1">data1</b><br>';
document.write(text[1] );
text[2] = '<b class="2">data2</b><br>';
document.write(text[2] );
text[3] = '<b class="3">data3</b><br>;
document.write(text[3] );
var jsArr=['js1.js', 'js2.js'];
for (var jsFile in jsArr) {
var script = document.createElement('script');
script.src = "/static/js/"+jsArr[jsFile];
document.body.appendChild(script[jsFile ]);
(function(script) {
return script.onload = function() {
console.log(script);
};
})(script);
}
<div class="countProduct">
<input class="countProduct__input" type="number" name="countProdict_id1" id="countProdict_id1" value="1">
<button type="button" onclick="quantityMinus('countProdict_id1')" class="countProduct__btn countProduct__btn--inc">
-
</button>
<button type="button" onclick="quantityPlus('countProdict_id1')" class="countProduct__btn countProduct__btn--dec">
+
</button>
</div>
<div class="countProduct">
<input class="countProduct__input" type="number" name="countProdict_id2" id="countProdict_id2" value="1">
<button type="button" onclick="quantityMinus('countProdict_id2')" class="countProduct__btn countProduct__btn--inc">
-
</button>
<button type="button" onclick="quantityPlus('countProdict_id2')" class="countProduct__btn countProduct__btn--dec">
+
</button>
</div>
function quantityMinus(target) {
let input = document.getElemetById(target);
if (input.value > 1) {
input.value= input.val() - 1;
}
}
function quantityPlus(target) {
let input = document.getElemetById(target);
input.value = input.value + 1;
}
<style>
.modal.fade{
display:none;
position: fixed;
top:50%;
left:50%;
background-color: aquamarine;
padding: 30px;
}
.modal.fade.open{
display:block;
}
</style>
<div id="modal" class="modal fade">
<div class="modal-dialog" role="document">
<div class="modal-content tx-size-sm">
<div class="modal-body tx-center pd-y-20 pd-x-20">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<i class="icon ion-ios-checkmark-outline tx-100 tx-success lh-1 mg-t-20 d-inline-block"></i>
<h4 class="tx-success tx-semibold mg-b-20">Поздравляем!</h4>
<p class="mg-b-20 mg-x-20"><?php echo $_SESSION['success']; unset($_SESSION['success']); ?></p>
<button type="button" class="btn btn-success pd-x-25" data-dismiss="modal" aria-label="Close">Продолжить</button>
</div>
</div>
</div>
</div>
<script type= text/javascript>
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById('modal').classList.add('open');
});
</script>
<form method="POST" id="fors" action="" name="formName" >
<input type="text" name="sum" value="">
<input onclick="checkDataAjax(event)" type="button" value="Проверить данные">
<input type="submit" id="btn" name="sum" value="Отправить" />
</form>
<div id="target"></div>
function checkDataAjax(event){
event.preventDefault();
form = new FormData(document.formName);
let options = {
method: "POST",
body:formData,
credentials: "include",
mode: 'cors'
};
let URL = "АдресВашегоСервера";
let request = new Request(URL, options);
fetch(request, options).then(function (response) {
return response.json();
}).then(function (response) {
document.getElementById('target').innerHTML = response;
}).catch(function (error) {
console.log(error);
});
}
<?php
$sum = $_POST["sum"];
if(!$sum)
{$sum = "Вы ничего не написали";}
echo $sum;
?>
<button class="btn-buy" onclick=cart.remove({"кроме":7})>
cart={
remove(data){
let blocks = document.getElementsByClassName("table-cart--section");
for (let block in blocks){
if (blocks[block].dataset.productid !== data["кроме"])
blocks[block].ParrentNode.RemoveChilde(blocks[block])
}
}
}
fetch(URL_forGetSelectData,
).then(function (response) {
return response.json();
}).then(function (response) {
// если даные пришли в виде html: '<option value="value_1">name_1</option><option value="value_n">name_n</option>'
document.getElementById("selectId").innerHTML=response;
// или если данные пришли в виде json примерно :
// response = {
// "name_1":"value_1",
// //...
// "name_n":"value_n",
// };
let fragment = document.createDocumentFragment();
for (let option in response){
let optionElem = new Option(option, response[option]);
fragment.appendChild(optionElem);
}
document.getElementById("selectId").appendChild(fragment);
return;
}).catch(function (error) {
console.log(error);
});