本文介绍了在UL和LI标签上添加隐藏值,如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有多个类似的选择:
<li>
<a href="#" title="" class="selected"><span class="to-admin">Administrator</span></a>
<input id="shareto" type="hidden" value="0-1" name="shareto">
</li>
<li>
<a href="#" title=""><span class="to-finance">Finance</span></a>
<input id="shareto" type="hidden" value="1-1" name="shareto">
</li>
<li>
<a href="#" title=""><span class="to-technician">Technician</span></a>
<input id="shareto" type="hidden" value="1-0" name="shareto">
</li>
<li>
<a href="#" title=""><span class="to-lawyer">Legal</span></a>
<input id="shareto" type="hidden" value="0-0" name="shareto">
</li>
现在我想使用此PHP'catch'该变量:
and now I want to 'catch' that variable using this PHP :
$Type = $_POST['shareto'];
为什么我总是得到最后一个值,无论我选择什么选项?如何正确做?
why I always get the last value, no matter what option I choose? how to do it correctly? thanks before.
推荐答案
请检查此工作提琴链接
Please check this working fiddle link http://jsfiddle.net/7GHug/
我认为您想要这样的东西。
I think you want something like this.
<ul>
<li data-val="0-1">
<a href="#" title="" class="selected"><span class="to-admin">Administrator</span></a>
</li>
<li data-val="1-1">
<a href="#" title=""><span class="to-finance">Finance</span></a>
</li>
<li data-val="1-0">
<a href="#" title=""><span class="to-technician">Technician</span></a>
</li>
<li data-val="0-0">
<a href="#" title=""><span class="to-lawyer">Legal</span></a>
<input id="shareto" type="hidden" value="" name="shareto">
</li>
</ul>
Javascritp
Javascritp
$(document).ready(function($) {
$('ul li').on('click', function() {
$('input#shareto').val($(this).data('val'));
});
});
通过单个隐藏输入,您可以基于单击的li更新值。
With single hidden input you can update the value based on the clicked li.
这篇关于在UL和LI标签上添加隐藏值,如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!