.按钮Bind事件和unBind事件

在如下的方法中 嵌套绑定  $("#btnCheck").bind("click", ParameterJson, InitPage);时候 必须使用 $("#btnCheck").unbind("click") 否则用户点击第一次,按钮执行一次该事件;用户点击第二次,按钮执行两次该事件;用户点击第N次,按钮执行N次该事件。

function InitPage() {
    try {
        var ResultJson = InitParameter();

        if (!ResultJson.Result) {
            alert(ResultJson.ErrorMessage);

            return false;
        }

        var ParameterJson = { pageUrl: strPageUrl, thWidth: strThWidth, divData: strDivData, divButton: strDivButton, QueryConditions: strQueryConditions };

        //初始化翻页按钮行
        ResultJson = PageButton(strPageUrl, strDivButton, strQueryConditions);

        if (!ResultJson.Result) {
            alert(ResultJson.ErrorMessage);

            return false;
        }

        if (!FirstPage(ParameterJson)) {
            alert("页面初始化失败!");

            return false;
        }

        //为“查询”按钮绑定事件
        $("#btnCheck").unbind("click");
        $("#btnCheck").bind("click", ParameterJson, InitPage);

        //为“首页”按钮绑定事件
        $("#spanFirstPage").bind("click", ParameterJson, FirstPage);

        //为“前一页”按钮绑定事件
        $("#imgPrePage").bind("click", ParameterJson, PrePage);

        //为“下一页”按钮绑定事件
        $("#imgNextPage").bind("click", ParameterJson, NexPage);

        //为“最后一页”按钮绑定事件
        $("#spanEndPage").bind("click", ParameterJson, EndPage);

        //为“跳转”按钮绑定事件
        $("#imgGo").bind("click", ParameterJson, GoPage);

        return true;
    }
    catch (ex) {
        alert("页面初始化失败!");
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
def load_excel(self, filename, menu_label, selected_label_text): self.la = menu_label self.workbook = xl.load_workbook(filename) self.sheet_names = sorted(self.workbook.sheetnames) # 按工作表名称从小到大排序 self.selected_label.config(text=selected_label_text) # 更新选中标签文本 # 清空左侧面板 for widget in self.sheet_frame.winfo_children(): widget.destroy() # 添加工作表按钮 for i, sheet_name in enumerate(self.sheet_names): button = tk.Button(self.sheet_frame, text=sheet_name, command=lambda name=sheet_name: self.show_sheet(name)) button.grid(row=i, column=0, sticky="ew", padx=1, pady=1) # 添加一个标记,表示该按钮未被使用 button.used = False # 绑定鼠标进入事件 button.bind("<Enter>", lambda event, button=button: button.configure(bg="lightgray")) # 绑定鼠标离开事件 button.bind("<Leave>", lambda event, button=button: button.configure(bg="SystemButtonFace")) # 绑定按钮的点击事件 button.bind("<Button-1>", lambda event, button=button: mark_used(button)) # 监听Canvas的大小变化,调整滚动条 self.sheet_frame.bind('<Enter>', lambda e: self.canvas.config(scrollregion=self.canvas.bbox("all"))) def mark_used(button): if not button.used: # 将按钮的标记设置为“已使用” button.used = True # 更改按钮的背景颜色 button.configure(bg="green") # 取消按钮的绑定事件 button.unbind("<Button-1>") # 绑定鼠标离开事件,使按钮的背景颜色保持不变 button.bind("<Leave>", lambda event, button=button: button.configure(bg="green")) for child in button.master.winfo_children(): # 绑定按钮的点击事件 child.bind("<Button-1>", lambda event, button=child: mark_used(button))def save_to_excel(self):將第一個函數中點擊按鈕后改變顔色添加到第二個函數中,
最新发布
05-30

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值