$("#goods_on").delegate(".ck_btn", "click", function (event) { if(isClick){ return false; } isClick =true; var a = $(this).parent().parent(); var id = $(this).attr("data-id"); var is_on = 0; var b = a.hasClass("car_on"); if (b) { a.removeClass("car_on"); is_on = 1; } else { a.addClass("car_on"); } $.ajax({ type: 'GET', url: "car.php?act=checks", data: {id: id, is_all: 3, is_on: is_on}, success: function (res) { if (res.error == 1) { alert("错误"); } else { ck_status(); changeAmount(res); //$("#count").text("¥" + res.total); } }, dataType: 'json' }); //防止恶意点击 setTimeout(function(){isClick =false;},700); event.preventDefault(); });是什么意思
时间: 2024-01-23 08:02:09 浏览: 27
这段代码使用了 jQuery 的 delegate() 方法,为 id 为 goods_on 的元素的子元素中所有 class 为 ck_btn 的元素绑定了 click 事件的处理函数。当点击这些元素时,会执行该函数中的代码。
函数中首先判断一个名为 isClick 的变量的值是否为 true,如果是,则直接返回 false,不执行后续代码;否则将 isClick 的值设为 true,并在 700 毫秒后将其设为 false,防止用户恶意多次点击。
接下来,获取点击元素的父元素的父元素 a,以及点击元素的 data-id 属性值 id,同时初始化一个名为 is_on 的变量为 0。然后判断父元素 a 是否有 class 为 car_on,如果有,则将 is_on 设为 1 并移除该 class,否则添加该 class。
最后,使用 jQuery 的 AJAX 方法向 car.php 发送一个 GET 请求,同时向服务器传递三个参数:id、is_all 和 is_on,其中 id 为上面获取的值,is_all 为 3,is_on 为上面计算得出的值。当服务器成功响应请求时,会执行 success 回调函数,根据响应数据中的 error 值来判断是否出现了错误,如果有错误则弹出 "错误" 的提示框,否则执行 ck_status() 和 changeAmount() 函数。
整个函数的功能是实现了购物车中商品的选中和不选中,同时更新购物车总价等信息。
相关问题
$("#goods_on").delegate(".gnum", "change", function () {
这是一个 jQuery 事件委托的代码片段,它的作用是当 `#goods_on` 元素内的 `.gnum` 元素(可能是动态添加的)的值改变时触发一个事件处理函数。
具体解释如下:
- `$("#goods_on")`:使用 jQuery 选择器选取 `id` 为 `goods_on` 的元素,这里可能是一个列表或表格等包含多个 `.gnum` 元素的容器。
- `.delegate()`:jQuery 1.7 版本之前,使用 `.delegate()` 方法来为动态添加的元素绑定事件,现在已经被 `.on()` 方法替代,不过仍然可以使用。
- `".gnum"`:选择要绑定事件的元素的 CSS 选择器。
- `"change"`:事件类型,表示当元素的值改变时触发事件。
- `function () { ... }`:事件处理函数,当事件被触发时执行其中的代码。
所以,当 `#goods_on` 元素内的 `.gnum` 元素的值改变时,会执行这个事件处理函数。可以在函数内部编写具体的逻辑处理代码。
转成cmake,HEADERS += \ $$PWD/AES/AES.h \ $$PWD/AutoSendDirectionCorrect/AutoSendDirectionCorrect.h \ $$PWD/HPSocket/HPSocket-SSL.h \ $$PWD/HPSocket/HPSocket.h \ $$PWD/HPSocket/HPSocket4C-SSL.h \ $$PWD/HPSocket/HPSocket4C.h \ $$PWD/HPSocket/HPTypeDef.h \ $$PWD/HPSocket/SocketInterface.h \ $$PWD/IFF/IFFDicts.h \ $$PWD/IFFDeal/IFFDeal.h \ $$PWD/IFFDeal/IFFStructFile.h \ $$PWD/IFFDeal/countrydata.h \ $$PWD/Itemdelegate/item_color_delegate.h \ $$PWD/Itemdelegate/item_height_delegate.h \ $$PWD/MyThreadSaveFile/mythreadsavefile.h \ $$PWD/MyUdpNode/my_udp_node.h \ $$PWD/PaUnitConvert/PaUnitConvert.h \ $$PWD/QMyDataDictionary/IniUtils.h \ $$PWD/QMyDataDictionary/QDataDictionary.h \ $$PWD/QMyLineEdit/QMyLineEdit.h \ $$PWD/QMyToolButton/QMyToolButton.h \ $$PWD/ST_Common/common.h \ $$PWD/RadarCommon/radar_result.h \ $$PWD/ST_Interpulse/interpulse_result.h \ $$PWD/ST_RadarCommon/RadarArrayConv.h \ $$PWD/ST_RadarCommon/RadarDicts.h \ $$PWD/ST_RadarCommon/iff.h \ $$PWD/ST_RadarCommon/radar_result.h \ $$PWD/ST_JamSrc/commonJamming.h \ $$PWD/global/global.h SOURCES += \ $$PWD/AES/AES.cpp \ $$PWD/AutoSendDirectionCorrect/AutoSendDirectionCorrect.cpp \ $$PWD/IFF/IFFDicts.cpp \ $$PWD/IFFDeal/IFFDeal.cpp \ $$PWD/CommunalData/CommunalData.cpp \ $$PWD/Itemdelegate/item_color_delegate.cpp \ $$PWD/Itemdelegate/item_height_delegate.cpp \ $$PWD/MyThreadSaveFile/mythreadsavefile.cpp \ $$PWD/MyUdpNode/my_udp_node.cpp \ $$PWD/QMyDataDictionary/IniUtils.cpp \ $$PWD/QMyDataDictionary/QDataDictionary.cpp \ $$PWD/QMyLineEdit/QMyLineEdit.cpp \ $$PWD/QMyToolButton/QMyToolButton.cpp \ $$PWD/ST_RadarCommon/RadarArrayConv.cpp \ $$PWD/ST_RadarCommon/RadarDicts.cpp \ $$PWD/global/global.cpp
你可以使用以下的 CMakeLists.txt 文件来转换这些源文件和头文件:
```
cmake_minimum_required(VERSION 3.1)
project(MyProject)
set(CMAKE_CXX_STANDARD 11)
set(SOURCES
AES/AES.cpp
AutoSendDirectionCorrect/AutoSendDirectionCorrect.cpp
CommunalData/CommunalData.cpp
IFF/IFFDicts.cpp
IFFDeal/IFFDeal.cpp
Itemdelegate/item_color_delegate.cpp
Itemdelegate/item_height_delegate.cpp
MyThreadSaveFile/mythreadsavefile.cpp
MyUdpNode/my_udp_node.cpp
QMyDataDictionary/IniUtils.cpp
QMyDataDictionary/QDataDictionary.cpp
QMyLineEdit/QMyLineEdit.cpp
QMyToolButton/QMyToolButton.cpp
ST_Common/common.cpp
ST_Interpulse/interpulse_result.cpp
ST_JamSrc/commonJamming.cpp
ST_RadarCommon/RadarArrayConv.cpp
ST_RadarCommon/RadarDicts.cpp
ST_RadarCommon/iff.cpp
ST_RadarCommon/radar_result.cpp
global/global.cpp
)
set(HEADERS
AES/AES.h
AutoSendDirectionCorrect/AutoSendDirectionCorrect.h
CommunalData/CommunalData.h
HPSocket/HPSocket-SSL.h
HPSocket/HPSocket.h
HPSocket/HPSocket4C-SSL.h
HPSocket/HPSocket4C.h
HPSocket/HPTypeDef.h
HPSocket/SocketInterface.h
IFF/IFFDicts.h
IFFDeal/IFFDeal.h
IFFDeal/IFFStructFile.h
IFFDeal/countrydata.h
Itemdelegate/item_color_delegate.h
Itemdelegate/item_height_delegate.h
MyThreadSaveFile/mythreadsavefile.h
MyUdpNode/my_udp_node.h
PaUnitConvert/PaUnitConvert.h
QMyDataDictionary/IniUtils.h
QMyDataDictionary/QDataDictionary.h
QMyLineEdit/QMyLineEdit.h
QMyToolButton/QMyToolButton.h
RadarCommon/radar_result.h
ST_Common/common.h
ST_Interpulse/interpulse_result.h
ST_JamSrc/commonJamming.h
ST_RadarCommon/RadarArrayConv.h
ST_RadarCommon/RadarDicts.h
ST_RadarCommon/iff.h
ST_RadarCommon/radar_result.h
global/global.h
)
add_executable(MyExecutable ${SOURCES} ${HEADERS})
```
这个 CMakeLists.txt 文件将所有的源文件和头文件添加到一个名为 MyExecutable 的可执行文件中。