Home  >  Article  >  Web Front-end  > 

Tag issue_html/css_WEB-ITnose

Tag issue_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:02:571126browse

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>

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>

but using ff6d136ddc5fdfeffaf53ff6ee95f18525edfb22a4f469ecb59f1190150159c6 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>

611a45f823f359e88668d8c4491919f7
$ (function(){
$("ul li").click(function(){
var ar = $(this).attr("name");
alert(ar);
})
})
611a45f823f359e88668d8c4491919f7
You just need to include a jquery yourself

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


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);}


<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'));  	});});

Statement:
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