从在jqGrid的gridComplete事件期间创建的按钮调用函数? [英] Call a function from a button that is created during jqGrid's gridComplete event?

查看:734
本文介绍了从在jqGrid的gridComplete事件期间创建的按钮调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在gridComplete事件期间创建的按钮的onclick事件中调用一个函数.加载成功…这是第一行中按钮呈现的html的样子

I'm trying to call a function in the onclick event of the button that is created during the gridComplete event..Loads OK…here's what the rendered html looks like for the button in the first row

<input type="button" onclick="deleteRow(9197113);" value="Delete" style="height: 22px; width: 70px;">

但是当我单击按钮时……函数没有被调用,并且萤火虫说了…….

but when i click the button…the function is not called and firebug says….

deleteRow未定义

deleteRow is not defined

我该如何调用一个函数,而不是使用内联javascript(它确实可以顺便说一句,但是我想调用该函数是为了提高可读性和可维护性).我已经包含了可工作的内联javascript ...在下面的代码段中已注释掉了...

How can I call a function, rather than having inline javascript,,,(which does work BTW, but I would like to call the function for readability and maintainability). I've included the working inline javascript...it's commented out in the below snippet...

下面是jqGrid设置的网格完成"部分.

Below is the grid Complete portion of the jqGrid settings.

jQuery("#list").jqGrid({

   ........................

    gridComplete: function() {
        var ids = jQuery("#list").jqGrid('getDataIDs');
        for (var i = 0; i < ids.length; i++) {
            var cl = ids[i];
            de = "<input style='height:22px;width:70px;' type='button' value='Delete' onclick='deleteRow('" + cl + "' );' />";   
            //de = "<input style='height:22px;width:70px;' type='button' value='Delete' onclick=\"jQuery('#list').jqGrid('delGridRow', '" + cl + "', {msg: 'Delete this entry?'});\" />"; 
            jQuery("#list").jqGrid('setRowData', ids[i], { Delete: de });
        }
    }

   ........................

 });

这是deleteRow()函数……

Here's the deleteRow() function…

function deleteRow() {
    alert("hit delete button");
    // jQuery("#grid_id").jqGrid('delGridRow', row_id_s,options );
}

推荐答案

我将更改网格完成功能,以便为输入提供一个说删除"的类,然后在我的文档就绪功能中为...设置实时单击事件该类选择器.

I would change your grid complete function so that it gives the imput a class of say "delete" and then in my document ready function setup a live click event for that class selector.

类似的东西

gridComplete: function() {
    var ids = jQuery("#list").jqGrid('getDataIDs');
    for (var i = 0; i < ids.length; i++) {
        var cl = ids[i];
        de = '<input style="height:22px;width:70px;" type="button" class="delete" value="Delete" />';
        $("#list").jqGrid('setRowData', ids[i], { Delete: de });
    }
}

$('#list .delete').live('click',function(){
    var id = $(this).parent().attr('id');
});

这篇关于从在jqGrid的gridComplete事件期间创建的按钮调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆