douchenchepan6465 2015-05-06 21:15
浏览 77
已采纳

如何onmouseover交换图像在PHP?

I have this code in my wordpress template

<a onclick="get_project_data(<?php echo get_the_ID(); ?>)"><img src="<?php echo wp_get_attachment_url( $logoimg_id ); ?>" onmouseover="this.src=\'<?php echo wp_get_attachment_url( $logoimg_id+b ); ?>';" onmouseout="this.src=\'<?php echo wp_get_attachment_url( $logoimg_id ); ?>';"/></a>

But it doesn't work, I need to show a full colour image and a black and white with on over, the thing is that I need to do this automatically so I will upload to my server photo.jpg and photob.jpg (black and white) css is not an option.

Thank you

  • 写回答

2条回答 默认 最新

  • duanji5569 2015-05-06 21:28
    关注

    First of all, you are not concatenating the strings correctly.

    $logoimg_id+'b' (notice the quotes)
    

    Secondly, you need to add the 'b' before the extension. You can do that by

    $imgPath = wp_get_attachment_url( $logoimg_id );
    $tmp = explode('.', $imgPath);
    $tmp[0].='b';
    $imgPath = implode('.',$tmp);
    

    Another way would be to do a

    echo str_replace('.jpg', 'b.jpg', wp_get_attachment_url( $logoimg_id ));
    

    But I would not advise it

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?