如何在js函数中传递图像路径

时间:2016-02-08 08:18:41

标签: javascript java jquery html jsp

我正在尝试使用JS函数将图像路径从一个JSP页面动态传递到另一个JSP页面,但是我在JS alert中获得的图像路径是不同的。正确的路径为.\Products\767\76\suitmed.jpg但警报会显示此.\Products>7>suitmed.jpg。有人可以帮我这个。

enter image description here

ProductDiv.jsp

<c:forEach items="${products}" var="products">
    <div class="col-sm-4">
        <div class="product-image-wrapper">
            <div class="single-products">
                <div class="productinfo text-center">
                    <!--here in this Image tag I was trying to pass the path od med and large img from product obj -->
                    <img src="${products.smallImage}" onclick="getImageDetails('${products.mediumImage}', '${products.largeImage}'); return false;" alt="${products.productId}+productImage" />
                    <h2>${products.allPrice}</h2>
                    <p>${products.name}</p>
                </div>
            </div>
            <div class="choose">
                <ul class="nav nav-pills nav-justified">
                    <li>
                        <a href="">
                            <i class="fa fa-plus-square"></i>
                            Add to Wishlist
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</c:forEach>

Product.Js

function getImageDetails(mediumImagePath, LargeImagePath) {
    alert(mediumImagePath + "_______" + LargeImagePath);
    $("#bigImage").attr("src", mediumImagePath);
}

产品详情.Jsp

<div class="view-product" >
    <img class="fancybox" id="bigImage" src="" data-big="images/home/suitlarge.jpg" /></br>
    <!--<img src="images/product-details/1.jpg" alt="" /> -->
    <h3>ZOOM</h3>
</div> 

1 个答案:

答案 0 :(得分:0)

从未编写过jsp,但这是一个看似合理的解释:

\ ##被解释为八进制字符转义序列。

Char    Octal   Dec Hex Description
<        74     60  3c  Less than sign (&lt; in HTML)
=        75     61  3d  Equals sign
>        76     62  3e  Greater than sign (&gt; in HTML)
?        77     63  3f  Question mark

所以&#34; \ 76&#34;成为&#34;&gt;&#34;打印时..

尝试替换所有&#34; \&#34;用&#34; /&#34;在通常可以帮助你的路径中,大多数web服务已经可以处理从unix样式路径转换为窗口样式的转换..