当前位置:网站首页>Several syntax for adding events to elements in a page
Several syntax for adding events to elements in a page
2022-06-10 00:22:00 【Envy the cloud but not the monarch】
One . Use the event attribute of the element :onxxx="f()"
Two . Use jquery object : Selectors .xxxx(function(){
//js
});
defects : This can only add events to intrinsic elements
Inherent elements : When an event function is called to add an event to an element , If the element has been generated , Then these elements are called intrinsic elements
Dynamically generated elements : When an event function is called to add an event to an element , If the element has not been generated , Later generated elements .
The wrong sample :
// When the main page of the campaign is loaded , Query the first page of all data and the total number of all data
queryActivityByConditionForPage(1,10);
// Add a stand-alone event to the query button
$("#queryActivityBtn").click(function () {
// Query the first page of all qualified data and the total number of all qualified data
queryActivityByConditionForPage(1,$("#demo_pag1").bs_pagination('getOption', 'rowsPerPage'));
});
$("#tBody input[type='checkbox']").click(function () {
// If all in the list checkbox All choose , this “ Future generations ” Button is also selected
if ($("#tBody input[type='checkbox']").size()==$("#tBody input[type='checkbox']:checked").size()){
$("#checkAll").prop("checked",true);
}else{// If all in the list checkbox At least one is not selected , The select all button is also cancelled
$("#checkAll").prop("checked",false);
}
})there $("#tBody input[type='checkbox']").click(function () The element has not been loaded when the function is executed : The element loading here is in queryActivityByConditionForPage(1,10); This function can only be loaded after the results are queried through asynchronous requests , Therefore, this is an asynchronous request. You won't continue to execute the following code until the result comes out , On the contrary, the synchronization request will wait for the results before continuing to execute the following code .
3、 ... and . Use jquery Of on Function to add events to dynamically generated elements :
Parent selector .on(" Event type "," Child selectors ",function(){
//js
});
Parent element : Must be an intrinsic element , It can be a direct parent element , It can also be an indirect parent element .
Event type : Follow event attributes and event functions A corresponding .
Child selectors : Target element , Form a parent-child selector with the parent selector
边栏推荐
猜你喜欢

可重复读隔离级别的基石MVCC机制

The cornerstone mvcc mechanism of repeatable read isolation level

低边驱动和高边驱动

Book club recruits | let's read "Mr. toad goes to see a psychologist"

IOS cache - nscache and sandbox cache

Opencv architecture

Johns Hopkins, Berkeley, California, etc. | using machine learning of sequence and structural features to achieve Generalized Prediction of antibody thermal stability

bias、variance介绍

SPSS主成分分析

没有项目管理经验,可以参加PMP考试?
随机推荐
pycharm 2022永久激活版下载,亲测有效
sparksql源码系列 | 一文搞懂Distribution源码体系(spark3.2)
尽一份孝心,为家人做一个老人防摔报警系统
View the installable version number of the wheel on this computer
Flutter ITMS-90338: Non-public API usage - Frameworks/webview_flutter_wkwebview.framework
(transfer) what is the difference between objectid, FID and oid fields in ArcGIS?
poi 导出excel实战
If (obj! = null) is not required
我服了,MySQL表500W行,居然有人不做分区?
15 charts to give you a deeper understanding of floating point numbers
sparksql源码系列 | 一文搞懂Partitioning源码体系(spark3.2)
打开xlsx文件时自动打开personal.xlsb表格文件
你了解单例模式吗?反正我不了解。
C WPF UI framework mahapps switching theme
The cornerstone mvcc mechanism of repeatable read isolation level
Ups and downs of network status
PMP高频知识整理
JVM explanation
Introduction to csrf/xsrf
Break that mirror and be yourself