有个问题想请教一下,我用ssh框架和easyui写的项目。点击一个超链接要跳转到写的界面。这其中我用点击事件传了一个ID,但是因为这个超链接所以发了三次请求。导致后两次ID为空了,这个该怎么做?
不知道你要的是不是这个:
<body>
<!-- 超链接href不做相应,使用js绑定跳转事件 -->
<a href="javascript:void(0);" id="testId">超链接</a>
</body>
<script type="text/javascript">
$(function(){
$("#testId").click(function(){
window.location.href = 'www.baidu.com?id=123456';
});
});
</script>
{field:" ",title:'筹款图片',width:100,align:'center',
formatter:function(value){
return "<a style='color:blue;text-decoration:none;' href='javascript:void(0);' onclick='img();'>点击查看</a>";
}} ,
$(document).ready(function() {
$('#friendsdg').datagrid({
onClickRow: function(rowIndex, rowData){
rows = $('#friendsdg').datagrid('getSelected');
$.ajax({
url: '<%=basePath %>friends/imgList.do',
type: 'post',//提交方式
data: { id: rows.id },//提交参数
success: function (result) {//ajax请求完成时执行,result为返回的结果
alert(result);
},
error: function () {
alert("ajax请求处理错误");
}
});
}
});
});
我把两段代码贴出来了
onclick='img();这个对应的img方法是处理什么的?你的easyui onClickRow已经执行了请求
目测是“事件冒泡”引起的,详情:http://blog.csdn.net/luanlouis/article/details/23927347
以下是处理后的代码:
formatter:function(value){
return "<a style='color:blue;text-decoration:none;' href='javascript:void(0);' onclick='img(event);'>点击查看</a>";
}
function img(e){
//阻止冒泡
if (e && e.stopPropagation){
e.stopPropagation()
}
else{
window.event.cancelBubble=true
}
console.log('img');
//下面再执行你的处理
}