我有一個<div class="custom">
內的變量$count
,如果另一個div類發生變化,我需要重新調整它。我寫了這樣的代碼如何刷新變化事件中的div內的變量?
$('.test1').on('change', function(e)) {
$('.custom').text($(this).text());
}
但它不刷新這個變量。
這裏是$ prod_count變量DIV塊
function commerce_popup_cart_block_view($delta=''){
$block = array();
switch($delta) {
case 'commerce_popup_cart':
global $user;
// Default to an empty cart block message.
$content = '';
// First check to ensure there are products in the shopping cart.
if ($order = commerce_cart_order_load($user->uid)) {
$wrapper = entity_metadata_wrapper('commerce_order', $order);
// Build the variables array to send to the cart block template.
$variables = array(
'order' => $order,
'contents_view' => commerce_embed_view('commerce_cart_block', 'defaults', array($order->order_id), $_GET['q']),
);
$count = commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types());
$quantity = 0;
foreach ($wrapper->commerce_line_items as $line_item) {
if (!$line_item instanceof EntityMetadataWrapper) {
$line_item = entity_metadata_wrapper('commerce_line_item', $line_item);
}
$types = array('product');
if (empty($types) || in_array($line_item->type->value(), $types)) {
$quantity = $quantity + $line_item->quantity->value();
}
}
$prod_count = t($quantity);
if ($prod_count > 0){
$icon = '<div class="cart-icon"></div><div class="cart_popup_count">'. $prod_count . '</div>';
$content = '<div id="cart-popup" style="display:none;">' . theme('commerce_cart_block', $variables) . '<div class="popup-arrow"></div></div>';
$content = '<div class="wrapper">' . $icon . $content . '</div>';
} elseif (variable_get('commerce_popup_cart_show_empty_cart', 0) == 1){
$content = commerce_popup_cart_block_view_get_empty_cart($variables);
}
}elseif (variable_get('commerce_popup_cart_show_empty_cart', 0) == 1){
$content = commerce_popup_cart_block_view_get_empty_cart($variables = array());
}
// If the superfish module is not installed then add hoverintent script
if (!module_exists('superfish')){
drupal_add_js(drupal_get_path('module','commerce_popup_cart') . '/js/jquery.hoverIntent.minified.js');
}
return array('subject' => t('Shopping cart'), 'content' => $content);
break;
}
return $block;
}
你有一個錯字:'function(e)){'而不是'function(e){'。 –
秒)在事件 – rick1
上關閉。不需要在函數聲明的結束'}之後執行。 –