Home > Web Front-end > HTML Tutorial >
Tag issue_html/css_WEB-ITnose

Tag issue_html/css_WEB-ITnose

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-24 12:02:57
Original
1202 people have browsed it

As mentioned, I want to use the

tag to achieve the select effect. How can I achieve this?

Just like this
<ul>    <li>张三</li>    <li>李四</li>    <li>王五</li></ul>
Copy after login

When I select Zhang San, I get the value 001 in the background, when I select Li Si, I get the value 002, and when I select Wang Wu, I get the value 001. The value is 003.
Please tell me how to implement


I know if it is written using select, it is
<select><option value="001">张三</option><option value="002">李四</option><option value="003">王五</option></select>
Copy after login

but using
  • does not work Know how to write


    Reply to discussion (solution)

    <ul>    <li name="001">张三</li>    <li name="002">李四</li>    <li name="003">王五</li></ul>
    Copy after login


    $ (function(){
    $("ul li").click(function(){
    var ar = $(this).attr("name");
    alert(ar);
    })
    })

    You just need to include a jquery yourself

    It’s just done by hand, it’s a bit wrong, I didn’t type 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


    Well, this is what I write now, but there is another question worth getting, for example:
    What I should get when clicking Zhang San is 001 , but what is actually obtained is 1, and 00 is automatically removed
    When I click on Li Si, I get 222. Normally
    When I click on Wang Wu, I get 0.
    When I click on Zhao Liu, I get 0.
    This Is there any solution?

    function getDriverId(obj) {	document.getElementById("driverId").value = obj.value;	alert(document.getElementById("driverId").value);}
    Copy after login


    <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>
    Copy after login

    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>
    Copy after login


    $(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'));  	});});
    Copy after login

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template