কিভাবে তৈরি করা: কর্মসূচি তালিকা
CSS এবং JavaScript ব্যবহার করে 'কর্মসূচি তালিকা' তৈরি করা শিখুন
To-do list
Use CSS and JavaScript to create a 'to-do list' to organize tasks and determine their priority.
Create a to-do list
প্রথম পদক্ষেপ - এইচটিএমএল যোগ করুন:
<div id="myDIV" class="header"> <h2>My To Do List</h2> <input type="text" id="myInput" placeholder="Title..."> <span onclick="newElement()" class="addBtn">Add</span> </div> <ul id="myUL"> <li>Hit the gym</li> <li class="checked">Pay bills</li> <li>Meet George</li> <li>Buy eggs</li> <li>Read a book</li> <li>Organize office</li> </ul>
দ্বিতীয় পদক্ষেপ - সিএসএস যোগ করুন:
শিরোনাম এবং তালিকার শৈলী সেট করুন:
/* অভ্যন্তরীণ মাঝারি এবং ঘিরে থাকা হোলডিং এলাকা যোগ করুন */ * { box-sizing: border-box; } /* তালিকা থেকে বাহ্যিক এবং অভ্যন্তরীণ মাঝারি সরান */ ul { margin: 0; padding: 0; } /* তালিকাভুক্তির শৈলী সেট করুন */ ul li { cursor: pointer; position: relative; padding: 12px 8px 12px 40px; background: #eee; font-size: 18px; transition: 0.2s; /* তালিকাভুক্তি নির্বাচনী করা যাবে না */ -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } /* সব বিন্দুত্বকারী তালিকাভুক্তি একটি ভিন্ন রঙে সেট করুন (ঝিনুমাটি) */ ul li:nth-child(odd) { background: #f9f9f9; } /* মাউস হটার সময় পিছনভূমির রঙ হাল্কা হয় */ ul li:hover { background: #ddd; } /* ক্লিক করার সময়, পিছনভূমির রঙ যোগ করুন এবং লিপিকে হাটান */ ul li.checked { background: #888; color: #fff; text-decoration: line-through; } /* ক্লিক করা হলে "প্রত্যক্ষ" মার্ক যোগ করুন */ ul li.checked::before { content: ''; position: absolute; border-color: #fff; border-style: solid; border-width: 0 2px 2px 0; top: 10px; left: 16px; transform: rotate(45deg); height: 15px; width: 7px; } /* বন্ধ বাটনের শৈলী নির্ধারণ */ .close { position: absolute; right: 0; top: 0; padding: 12px 16px 12px 16px; } .close:hover { background-color: #f44336; color: white; } /* শীর্ষের শৈলী নির্ধারণ */ .header { background-color: #f44336; padding: 30px 40px; color: white; text-align: center; } /* শীর্ষকের পরের ফ্লোটিং নিরসন */ .header:after { content: ""; display: table; clear: both; } /* ইনপুট ফিল্ডের শৈলী নির্ধারণ */ input { margin: 0; border: none; border-radius: 0; width: 75%; padding: 10px; float: left; font-size: 16px; } /* "যোগ করুন" বাটনের শৈলী নির্ধারণ */ .addBtn { padding: 10px; width: 25%; background: #d9d9d9; color: #555; float: left; text-align: center; font-size: 16px; cursor: pointer; transition: 0.3s; border-radius: 0; } .addBtn:hover { background-color: #bbb; }
তৃতীয় পদক্ষেপ - জাভাস্ক্রিপ্ট যোগ করুন:
// প্রত্যেক তালিকা আইটেমের জন্য একটি "বন্ধ" বাটন তৈরি করে এবং তাকে যুক্ত করুন var myNodelist = document.getElementsByTagName("LI"); var i; for (i = 0; i < myNodelist.length; i++) { var span = document.createElement("SPAN"); var txt = document.createTextNode("\u00D7"); span.className = "close"; span.appendChild(txt); myNodelist[i].appendChild(span); } // 单击关闭按钮以隐藏当前列表项 var close = document.getElementsByClassName("close"); var i; for (i = 0; i < close.length; i++) { close[i].onclick = function() { var div = this.parentElement; div.style.display = "none"; } } // 单击列表项时添加一个“已选中”符号 var list = document.querySelector('ul'); list.addEventListener('click', function(ev) { if (ev.target.tagName === 'LI') { ev.target.classList.toggle('checked'); } }, false); // 单击“添加”按钮时创建一个新的列表项 function newElement() { var li = document.createElement("li"); var inputValue = document.getElementById("myInput").value; var t = document.createTextNode(inputValue); li.appendChild(t); if (inputValue === '') { alert("You must write something!"); } else { document.getElementById("myUL").appendChild(li); } document.getElementById("myInput").value = ""; var span = document.createElement("SPAN"); var txt = document.createTextNode("\u00D7"); span.className = "close"; span.appendChild(txt); li.appendChild(span); for (i = 0; i < close.length; i++) { close[i].onclick = function() { var div = this.parentElement; div.style.display = "none"; } } }