doutiaoku4495 2012-02-09 13:12
浏览 39
已采纳

需要PHP到多个str_replace和jQuery text.replace

I have this line of code that will replace special character in php:

<?php echo str_replace(" +12,00$,"1200",$this->htmlEscape($_image->getLabel())) ?>" />

for this to work as i need, also the jQuery will have to include this code in other call:

jQuery("#productImg" + optionValueText.replace(' +12,00€','1200')).fadeIn('slow');

This will outpout 1200 and it will work good to add a span id for an image to load. But i will have multiple prices, so i need automatic to do the work.

I need to make both codes to remove white space in the beggining and characters + , from the price so allways it will display the price as 1200,4400,3399 etc. For php i think i can do it if i play some time with the code but for jQuery line also?

Can somebody provide both codes please?

Thank you very much for your kind help!

EDIT: the full php code that will load the image:

<a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=999,height=999,left=666,top=333,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;">
<span style="margin-top:-212px;"> <img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" alt="no image" id="productImg<?php echo str_replace(" +12,00€","1200",$this->htmlEscape($_image->getLabel())) ?>" /></a></span>    

and the jQuery that on dropdown change will control what image to hide and show.

jQuery(document).ready(function() {

// On document ready hide all images first

jQuery(".product-image2 img").hide();
jQuery("#off").hide();
jQuery("#productImgDefault").show();

jQuery("#<?=$colour_select_id ?>").change(function() {
    // Hide all images on slect element change action
     jQuery(".product-image img").hide();
     jQuery(".product-image2 img").hide();
      jQuery("#productImgDefault").hide(); 
         jQuery(".product-image .mousetrap").hide();                        


    // Get the value of selected option
    var optionValue = jQuery(this).attr('value');
    // Just a test to see if you're getting option value
    // alert(optionValue);

    // Get the content (aka inner HTML) of selected option
    var optionValueText = jQuery.trim(jQuery('#<?=$colour_select_id ?> :selected').text());

    // Just a test to see if you're getting right selected option inner text
    // alert(optionValueText);
 //  alert('Selected option has value: ' + optionValue + ' and inner text: ' + optionValueText);

    // Show the image based on selected value
    // Whatch out, case sensitive...

  if(optionValueText == "-- choose --") {
    jQuery(".product-image .mousetrap").show(); 
     jQuery("#on").fadeIn('slow');
      jQuery("#off").hide();
jQuery("#productImgDefault").fadeIn('slow'); } else { jQuery("#productImg" + optionValueText.replace(' +12,00€','1200')).fadeIn('slow');
  jQuery("#off").fadeIn('slow');
  jQuery("#on").hide();
}
  });

});
  • 写回答

2条回答 默认 最新

  • doujianzhi3358 2012-02-09 13:48
    关注

    Javascript:

    optionValueText.replace(/[\+\s\$\,\€]/g,'');
    

    PHP:

    echo preg_replace('/[\+\s\$\,\€]/','', $this->htmlEscape($_image->getLabel()));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程