You can change the code to check if 'item_id' has a value and then use it to find the element with that specific id. Here's an example:

if (item_id) {
  $('#' + item_id).closest('.qcart_item').find('.qq_item_data').each(function() {
    // Your code here
  });
}

This code first checks if 'item_id' has a value (i.e., it is not empty or null). If it has a value, it uses it to find the element with that id. Then, it performs the desired operation ('each' function in this case) on the found element.

jQuery: Check If ID Exists Before Using It in a Selector

原文地址: https://www.cveoy.top/t/topic/qdba 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录