页面:
{volist name="list" id="vo"}
<li>
<a href="javascript:;" onclick="checkUser({$vo.id})">
<div class="img">
<img src="{$vo.pic}">
</div>
<div class="desc">
<div style='width:190px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;' class="t">{$vo.title}</div>
<div class="info">
<span>{$vo.gname}</span>
<span><i class="play"></i>{$vo.times}分钟</span>
<span><i class="eye"></i>{$vo.plays}</span>
</div>
</div>
</a>
</li>
{/volist}
JS:
<script type="text/javascript">
function checkUser(id) {
$.ajax({
type: "POST",
dataType: "json",
url: "{:url('index/play')}?vid="+id,
data: {},
success: function (result) {
if (result.code == 1) {
new NoticeJs({
text: result.msg,
position: 'middleCenter',
animation: {
open: 'animated bounceInRight',
close: 'animated bounceOutLeft'
}
}).show();
}
},
error : function() {
new NoticeJs({
text: '异常',
position: 'middleCenter',
}).show();
}
});
}
</script>
思路:在点击事件里面传入循环的id值,否则只能固定获取一个id。
|