简体   繁体   中英

How to pass image path in js function

I'm trying to pass the image path dynamically from one JSP page to another using a JS function, but the image path I get in a JS alert is different. The correct path is .\\Products\\767\\76\\suitmed.jpg however the alert shows me this .\\Products>7>suitmed.jpg . Can some one please help me with this.

在此处输入图片说明

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);
}

Product details.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> 

Never programmed jsp, but here is a plausible explanation:

\\## is interpreted as an octal character escape sequence.

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

so "\\76" becomes ">" when printing..

try replacing all "\\" with "/" in paths that usually helps you out, and most webservices can already handle the translation from unix styled paths to windows styled..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM