单击Button后显示消息

时间:2015-12-30 12:04:38

标签: javascript css magento

我们正在使用此代码进行定价。点击更新按钮后,我们会收到“更新”消息enter image description here

<input class="ama1" type = "text" id = "price_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name= "price[]" value = "<?php echo $products->getPrice(); ?>" style = ""/>

<input type="hidden" name="curr_<?php echo $products->getId(); ?>" id="curr_<?php echo $products->getId(); ?>" value="<?php echo $products->getPrice(); ?>" />

<p id="updatedprice_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>
<br/>

<button id="price_update_button_<?php echo $products->getId(); ?>" class="update" onclick="updateFieldPrice('<?php echo $products->getId(); ?>'); return false;" >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>

<button id="price_reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideResetPrice('<?php echo $products->getId(); ?>','<?php echo $products->getPrice(); ?>'); return false;">
<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>

以同样的方式,我们将此代码用于数量:

<?php
$selllermpassignproduct=Mage::getModel('mpassignproduct/mpassignproduct')->getAssignProDetails($products->getId());
//Zend_Debug::dump($selllermpassignproduct,null,true);
$stock_item=Mage::getModel('cataloginventory/stock_item')->loadByProduct($products);

$SellerQty=isset($selllermpassignproduct['sellerqty'])?$selllermpassignproduct['sellerqty']:$stock_item->getQty();
$assignqty=isset($selllermpassignproduct['assignqty'])?$selllermpassignproduct['assignqty']:0;
?>


<input class="ama1" type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "stock" value = "<?php echo (int) $SellerQty; ?>" />


<p id="updatedqty_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>
<br/>


<button id="update_button_<?php echo $products->getId(); ?>" class="update" onclick="updateField('<?php echo $products->getId(); ?>',<?php echo $assignqty;?>); return false;"  >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>

<button id="reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideReset('<?php echo $products->getId(); ?>'); return false;"  >
<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>

但我们没有收到任何类似“已更新”的消息。以下代码是该消息的原因。

价格

<p id="updatedprice_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>

数量

<p id="updatedqty_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>

价格的JS代码

function hideResetPrice(product_id,priceold) { 

var qtyId='#price_'+ product_id; 
var currprice='#curr_'+ product_id; 
var editLink="#price_edit_link_"+ product_id; 
var updateButton="#price_update_button_"+ product_id; 
var valueprice="#valueprice_"+ product_id; 
var resetButton="#price_reset_button_"+ product_id; 


$wk_jq(valueprice).show(); 
$wk_jq(qtyId).val( $wk_jq(currprice).val()); 
$wk_jq(editLink).show(); 

}



function showFieldPrice(product_id)
        {

            var qtyId='#price_'+ product_id;

            var editLink="#price_edit_link_"+ product_id;
            var valueprice="#valueprice_"+ product_id;
            var updateButton="#price_update_button_"+ product_id;
            var resetButton="#price_reset_button_"+ product_id;

            $wk_jq(qtyId).show();
            $wk_jq(valueprice).hide();

            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(updateButton).prop('disabled', false);//just in case
            $wk_jq(resetButton).show();

            return false;


        }


function updateFieldPrice(product_id) 
{ 
var priceId = '#price_'+ product_id; 
var currprice='#curr_'+ product_id; 
var updatedqty = '#updatedprice_'+ product_id; 
var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateFieldPrice/')?>'; 
$price = $wk_jq(priceId).val(); 
$wk_jq(currprice).val($price); 
new Ajax.Request(url, { 
method: 'post', 
parameters: {id: product_id, price: $price}, 
onComplete: function (transport) { 
//alert(transport.responseText); 

jQuery(updatedqty).show().delay(2000).fadeOut(); 

} 
}); 
}

数量的Js代码

function hideReset(product_id) {

            var qtyId='#qty_'+ product_id;
            var editLink="#edit_link_"+ product_id;
            var updateButton="#update_button_"+ product_id;
            var resetButton="#reset_button_"+ product_id;


            $wk_jq(editLink).show();

        }

function showField(product_id)
        {

            var qtyId='#qty_'+ product_id;

            var editLink="#edit_link_"+ product_id;
            var updateButton="#update_button_"+ product_id;
            var resetButton="#reset_button_"+ product_id;

            $wk_jq(qtyId).show();

            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(updateButton).prop('disabled', false);//just in case
            $wk_jq(resetButton).show();

            return false;


        }

function updateField(product_id,assignqty)
        {
            var qtyId = '#qty_'+ product_id;
            var valueId = '#valueqty_'+ product_id;
            var updatedqty = '#updatedqty_'+ product_id;


            var editLink = "#edit_link_"+ product_id;
            var updateButton = "#update_button_"+ product_id;
            var resetButton = "#reset_button"+ product_id;
            var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateField/')?>';



            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(resetButton).show();

            $qty = $wk_jq(qtyId).val();
            jQuery(valueId).html($qty);
            hideReset(product_id);

            var tmpQty=assignqty+ parseInt($qty) ;

            new Ajax.Request(url, {
                method: 'post',
                parameters: {id: product_id, qty: tmpQty},
                onComplete: function (transport) {
                    //alert(transport.responseText);
                    jQuery(priceId).val($price);
            // $wk_jq(priceId).setValue($price);

                    jQuery(updatedqty).show().delay(2000).fadeOut();

                    $updateButton.prop('disabled', false);

                    // $wk_jq(qtyId).setValue($qty);



                }
            });
        }

2 个答案:

答案 0 :(得分:1)

new Ajax.Request(url, {
                method: 'post',
                parameters: {id: product_id, qty: tmpQty},
                onComplete: function (transport) {
                    //alert(transport.responseText);
                    jQuery(priceId).val($price);
            // $wk_jq(priceId).setValue($price);

                    jQuery(updatedqty).show().delay(2000).fadeOut();

                    $updateButton.prop('disabled', false);

                    // $wk_jq(qtyId).setValue($qty);



                }
            });

替换为

      new Ajax.Request(url, {
            method: 'post',
            parameters: {id: product_id, qty: tmpQty},
            onComplete: function (transport) {
                //alert(transport.responseText);
                //jQuery(priceId).val($price);
        // $wk_jq(priceId).setValue($price);

                jQuery(updatedqty).show().delay(2000).fadeOut();

                $updateButton.prop('disabled', false);

                // $wk_jq(qtyId).setValue($qty);



            }
        });

答案 1 :(得分:1)

使用此var updatedqty = "#updatedqty_"+ product_id; 在var ""上使用双引号updatedqtyfunction updateField(product_id,assignqty)

这里我可以看到没有那个变量就可以了。

function updateField(product_id,assignqty)
    {
        var qtyId ="#qty_"+ product_id;
        var valueId ="#valueqty_"+ product_id;
        var updatedqty ="#updatedqty_"+ product_id;
        var editLink ="#edit_link_"+ product_id;
        var updateButton ="#update_button_"+ product_id;
        var resetButton ="#reset_button"+ product_id;
        var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateField/')?>';



        $wk_jq(editLink).hide();
        $wk_jq(updateButton).show();
        $wk_jq(resetButton).show();

        $qty = $wk_jq(qtyId).val();
        jQuery(valueId).html($qty);
        hideReset(product_id);

        var tmpQty=assignqty+ parseInt($qty) ;

        new Ajax.Request(url, {
            method: 'post',
            parameters: {id: product_id, qty: tmpQty},
            onComplete: function (transport) {
                //alert(transport.responseText);
               // jQuery(priceId).val($price);
                // $wk_jq(priceId).setValue($price);

                jQuery(updatedqty).show().delay(2000).fadeOut();

                $updateButton.prop('disabled', false);

                // $wk_jq(qtyId).setValue($qty);

            }
        });
    }