المشكله هي في ميزة ال update عندما اقوم ب عمل update فأنها لا تقوم بالعمل بشكل جيد
و عندما اقوم بعمل creat ينشأ لي عنصرين و ليس عنصر واحد
مع اني حاولت كثيرا لكي اقوم بأصلاح المشاكل التاليه
ما هو الحل و شكرا
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><linkrel="stylesheet"href="pstyle.css"><metaname="viewport"content="width=device-width, initial-scale=1.0"><linkrel="preconnect"href="https://fonts.googleapis.com"><linkrel="preconnect"href="https://fonts.gstatic.com"crossorigin><linkhref="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap"rel="stylesheet"><title>CRUDs</title></head><body><divclass="crud"><!-- ----- --><divclass="head"><h2><imgsrc="/project/photos/cruds.png"alt=""width="40px"><p>crud</p></h2><atarget="_blank"href="/ourTeam.html"class="ourTeam">Our Team</a></div><!-- ----- --><divclass="inputs"><inputtype="text"name=""id="title"placeholder="title"><divclass="price"><inputonkeyup="getTotal()"type="number"value=""id="price"placeholder="price"><inputonkeyup="getTotal()"type="number"value=""id="taxes"placeholder="taxes"><inputonkeyup="getTotal()"type="number"value=""id="ads"placeholder="ads"><inputonkeyup="getTotal()"type="number"value=""id="discount"placeholder="discount"><smallid="total"></small></div><divclass="containerOfcreat"><divclass="creatdiv"><inputtype="text"id="count"placeholder="count"><inputtype="text"id="category"placeholder="category"></div><buttonid="submit"><imgsrc="/project/photos/creat.png"alt="noIMGerror"width="20px"> Creat</button></div></div><!-- ----- --><divclass="outputs"><divclass="searchBlock"><inputtype="text"id="search"placeholder="search"><divclass="btnSearch"><buttonid="searchTitle">Search By Title</button><buttonid="searchTCategory">Search By Category</button></div></div></div><divid="deletAll"></div><table><tr><th>id</th><th>title</th><th>price</th><th>taxes</th><th>discount</th><th>total</th><th>ads</th><th>category</th><th>update</th><th>delet</th></tr><tbodyid="tbody"></tbody></table></div><footer><p>Proudly made by Mohammed Haimour 😁</p></footer><scriptsrc="JSfile.js"></script></body></html>
let title = document.getElementById("title");
let price = document.getElementById("price");
let taxes = document.getElementById("taxes");
let ads = document.getElementById("ads");
let discount = document.getElementById("discount");
let total = document.getElementById("total");
let count = document.getElementById("count");
let category = document.getElementById("category");
let submit = document.getElementById("submit");// console.log(title ,price ,taxes ,ads ,discount, total,count,category,submit);
let mood ="creat";
let tmp;// count totalfunction getTotal(){if(price.value !=""){
let result =+price.value ++ads.value ++taxes.value -+discount.value;
total.innerHTML = result;
total.style.background ="#040";}else{
total.innerHTML ="";
total.style.background ="#421";}}// creat product// pro == product
let dataPro;if(localStorage.product !=null){
dataPro = JSON.parse(localStorage.product);}else{
dataPro =[];}
submit.onclick =function(){
let newPro ={
title: title.value,
price: price.value,
taxes: taxes.value,
ads: ads.value,
discount: discount.value,
total: total.innerHTML,
count: count.value,
category: category.value,};if(mood ==="creat"){if(newPro.count >1){for(let i =0; i < newPro.count; i++){
dataPro.push(newPro);}}else{
dataPro.push(newPro);}}else{
dataPro[tmp]= newPro;}
dataPro.push(newPro);// save localstorage
localStorage.setItem("product", JSON.stringify(dataPro));
clearData();};// clear inouptsfunction clearData(){
title.value ="";
price.value ="";
taxes.value ="";
total.innerHTML ="";
count.value ="";
category.value ="";}// readfunction showData(){
let tabel ="";for(let i =0; i < dataPro.length; i++){
tabel +=`<tr><td>${i}</td><td>${dataPro[i].title}</td><td>${dataPro[i].price}</td><td>${dataPro[i].taxes}</td><td>${dataPro[i].ads}</td><td>${dataPro[i].discount}</td><td>${dataPro[i].total}</td><td>${dataPro[i].category}</td><td><button onclick="updateData(${i})" id="update">update</button></td><td><button onclick="deletData(${i})" id="delet">delet</button></td></tr>`;}
document.getElementById("tbody").innerHTML = tabel;
let btnDelt = document.getElementById("deletAll");if(dataPro.length >0){
btnDelt.innerHTML =`<button onclick="deletAll()">delet All-${dataPro.length}-</button>`;}else{
btnDelt.innerHTML ="";}}
showData();var newww = showData();// deletfunction deletData(i){
dataPro.splice(i,1);
localStorage.product = JSON.stringify(dataPro);
showData();}function deletAll(){
localStorage.clear();
dataPro.splice(0);
showData();}// count// updatefunction updateData(i){
title.value = dataPro[i].title;
price.value = dataPro[i].price;
taxes.value = dataPro[i].taxes;
ads.value = dataPro[i].ads;
discount.value = dataPro[i].discount;
getTotal();
count.style.display ="none";
category.value = dataPro[i].category;
submit.innerHTML ="Update";
mood ="update";
tmp = i;}// search// clean data
السؤال
Mohammed Hhhh
السلام عليكم و رحمة الله وبركاته
انا اقوم بعمل مشروع crud و لكن صادفتني مشكله
المشكله هي في ميزة ال update عندما اقوم ب عمل update فأنها لا تقوم بالعمل بشكل جيد
و عندما اقوم بعمل creat ينشأ لي عنصرين و ليس عنصر واحد
مع اني حاولت كثيرا لكي اقوم بأصلاح المشاكل التاليه
ما هو الحل و شكرا
7 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.