Home > Article > Web Front-end >
As mentioned, I want to use the ff6d136ddc5fdfeffaf53ff6ee95f18525edfb22a4f469ecb59f1190150159c6929d1f5ca49e04fdcb27f9465b944689bed06894275b65c1ab86501b08a632eb tag to achieve the select effect. How can I achieve this?
Just like this
<ul> <li>张三</li> <li>李四</li> <li>王五</li></ul>
<select><option value="001">张三</option><option value="002">李四</option><option value="003">王五</option></select>
<ul> <li name="001">张三</li> <li name="002">李四</li> <li name="003">王五</li></ul>
It’s just done by hand, it’s a bit wrong, I didn’t type 187a5c8f3ec96216b16027c4a69cf4c3 below, you can test it
If it is a form submission, you can set a hidden field in the form. When you click li, just change the value of the hidden field, and finally submit the form
You click ul When changing the value of select
Well thank you
If it is a form submission, you can set a hidden field in the form, and when you click li, change the hidden field The value is enough, and finally submit the form
function getDriverId(obj) { document.getElementById("driverId").value = obj.value; alert(document.getElementById("driverId").value);}
<input type="hidden" id="driverId" name="driverId" value="" /><ul> <li value="001" onclick='getDriverId(this)'>张三</li> <li value="222" onclick='getDriverId(this)'>李四</li> <li value="12345678910" onclick='getDriverId(this)'>王五</li> <li value="测试" onclick='getDriverId(this)'>赵六</li> </ul>
The problem has been solved, thank you all, the solution code is as follows:
<div class="ddl collapse driver cover-3"> <input type="hidden" id="driverId" name="driverId" value="" /> <input type="text" placeholder="" readonly> <ul> <li data-value="001">张三</li> <li data-value="111111">李四</li> <li data-value="12345678910">哈哈</li> <li data-value="你好">哇哈哈</li> </ul></div>
$(document).ready(function() { 'use strict'; var $driver = $('.driver'), $list = $driver.children('ul'); $list.delegate('li', 'click', function() { var $this = $(this); $driver.value = $this.attr('data-value'); //alert($driver.value); //alert($this.attr('data-value')); });});