HTML5为我们提供了一个强大的功能,前段也也能实现后台数据库的效果,例如data-xxx
<a href="#myModal" data-industry_id="{$industry_info.industry_id}" class="del_btn" role="button" data-toggle="modal"><i class="fa fa-trash-o"></i></a>
其中,我在data-industry_id中存放了一个数据,我要拿出来,就:
<script type="text/javascript"> //获取数据 var industry_id = ''; $('.del_btn').click(function(){ industry_id = $(this).attr('data-industry_id'); });
其中id='del_btn'的我为他设置了一个点击事件,以点击他就获取 data-industry_id 的数据,这样就可以取出来了。
如果其中href如果被占据了,则可以在JavaScript设置:
//点击事件 $('.btn-danger').click(function(){ window.location.href = '{:U("Industry/industry_delete")}?industry_id=' + industry_id; });