如何使用javascript获取产品_图像1到4对象路径中存在图像的长度
在webservice 1中类似于此如何使用javascript获取产品_图像1到4对象路径中存在图像的长度,javascript,Javascript,在webservice 1中类似于此 "product_image1":"http://XYZ.co.uk/product_img/big/1_14238411703234.JPG" , "product_image2":"http://XYZ.co.uk/product_img/big/2_14238411703234.JPG" , "product_image3":"http://XYZ.
"product_image1":"http://XYZ.co.uk/product_img/big/1_14238411703234.JPG" ,
"product_image2":"http://XYZ.co.uk/product_img/big/2_14238411703234.JPG" ,
"product_image3":"http://XYZ.co.uk/product_img/big/",
"product_image4":"http://XYZ.co.uk/product_img/big/",
"product_image1":"http://XYZ.co.uk/product_img/big/1_14303945253625.jpg" ,
"product_image2":"http://XYZ.co.uk/product_img/big/2_14303945253625.jpg" ,
"product_image3":"http://XYZ.co.uk/product_img/big/3_14303945253625.jpg",
"product_image4":"http://XYZ.co.uk/product_img/big/4_14303945253625.png",
在webservice 2中类似于此
"product_image1":"http://XYZ.co.uk/product_img/big/1_14238411703234.JPG" ,
"product_image2":"http://XYZ.co.uk/product_img/big/2_14238411703234.JPG" ,
"product_image3":"http://XYZ.co.uk/product_img/big/",
"product_image4":"http://XYZ.co.uk/product_img/big/",
"product_image1":"http://XYZ.co.uk/product_img/big/1_14303945253625.jpg" ,
"product_image2":"http://XYZ.co.uk/product_img/big/2_14303945253625.jpg" ,
"product_image3":"http://XYZ.co.uk/product_img/big/3_14303945253625.jpg",
"product_image4":"http://XYZ.co.uk/product_img/big/4_14303945253625.png",
我的代码:-
items+='<img id="slideImgId3" src='+item.product_image1+' class="detailShowBigImg">';
items+='<img src='+item.product_image1+' onclick="changeImage3(\''+item.product_image1+'\');" class="multiImgShow">';
items+='<img src='+item.product_image2+' onclick="changeImage3(\''+item.product_image2+'\');" class="multiImgShow">';
items+='<img src='+item.product_image3+' onclick="changeImage3(\''+item.product_image3+'\');" class="multiImgShow">';
<script type="text/javascript">
function changeImage3(img3)
{
document.getElementById("slideImgId3").src=img3;
}
</script>
items+='';
项目+='';
项目+='';
项目+='';
功能更改图像3(img3)
{
document.getElementById(“slidemgid3”).src=img3;
}
您可以看到webservice1和webservice2。在webservice 1中,有product_image3和product_image4没有映像,而在webservice 2中,所有对象映像都存在,因此如何解决此问题并使其动态化。尝试这组代码
var img = document.getElementById('imageid');
//or however you get a handle to the IMG
var width = img.clientWidth;
var height = img.clientHeight;
试试这套代码
var img = document.getElementById('imageid');
//or however you get a handle to the IMG
var width = img.clientWidth;
var height = img.clientHeight;
我认为如果您知道图像是.jpg或.png,您可以使用正则表达式执行以下操作:
在那里,如果没有图像,您将得到null我想如果您知道图像是.jpg或.png,您可以使用正则表达式来执行以下操作: 如果(item.product_image1!=”{items+='';}使用此项仅显示具有完整图像路径的图像,则在没有图像的情况下将获得null。如果(item.product_image1!=”{items+='';}使用此项仅显示具有完整图像路径的图像。