<li class='nav-has-sub'><a href='#' id="selectval">选择直播房间</a>
<input type="hidden" name="id" value="" id="idval">
<ul>
<?php foreach($livelist as $val) { ?>
<li class='nav-has-sub'><a href='#'><?php echo $val['categoryName']; ?></a>
<ul>
<?php foreach($val['child'] as $v) { ?>
<li ><a href='#' class="ev" value='<?php echo $v['channelId']; ?>'><?php echo $v['name']; ?> </a></li>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul>
$(".ev").click(function(){
var value=$(this).text();
var id=$(this).attr("value");
$("#idval").val(id);
$("#selectval").html(value);
})
先给一个value属性,在把值覆给隐藏域就可以,加上name值