很多时候jquery只能或者应该回去一个集合。然后通过this获取触发时间的对象及相关属性
this.jq('#needsType').on("click", ".selection", function (e) { e.stopPropagation();
//获取父级元素,使得隐藏的ul在添加on方法后显示出来 var that = $(this).parent(); console.log(that); that.addClass('on'); that.find('ul li').click(function () {
//获取当前点击元素的data属性的val值 var val= $(this).data('val'); that.find('input[type=text]').val($(this).text()); that.removeClass('on'); }); });
网页部分
<div >已回答</li>
</ul>
</div>