Below is a snippet I used to create a <ul>
list. I will be adding <li>
with the help of jQuery. Please help me with how to add multi-selection to <li>
items.
<div class="projects">
<ul class="menu" id="projects-menu">
</ul>
</div>
li elements are added as below
$('#projects-menu').append("<li id='li-select' value = '"+String.raw`${value[projectName]}`+"'>"+projectName+"</li>")
The result is something as shown in the image.
This works here. Import jQuery first and use a select tag instead of ul:
<script type="text/javascript">
$(document).ready(function () {
var options = ['Apple', 'Banana', 'Orange'];
$("#projects-menu").append(new Option('Select a fruit', 0, true, true)).trigger("change");
// Default option
options.forEach(o => $("#projects-menu").append(new Option(o, o, false, false)).trigger("change"));
$("#projects-menu").on("change", function () {
const selectedValue = $(this).val();
console.log(selectedValue);
});
})
</script>
We can use this follow steps: -1st you can put jQuery links in the head section
<html> <head> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> <script src="https://code.jquery.com/jquery-3.5.1.min.map"></script> </head> <body> </body> </html>
2nd step is to use with an id attribute then we can use javascript a JSON.JS
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.