我正在使用博客,我正在尝试在帖子中使用BBcode时显示内容
在控制台中我收到错误:"未捕获TypeError:无法读取属性' src'未定义'"
我有代码,我尝试了找到的方法,但它仍然无法解决
function detailsp(e, t, n) {
var r = e.substring(7);
e = document.getElementById(e);
var i = ""
, s = e.getElementsByTagName("img");
1 <= s.length && (i = '<img src="' + s[0].src + '"/>');
var oldprice = e.innerHTML.substring(e.innerHTML.indexOf("[oldprice]") + 10, e.innerHTML.indexOf("[/oldprice]"))
, u = e.innerHTML.substring(e.innerHTML.indexOf("[price]") + 7, e.innerHTML.indexOf("[/price]"));
pricevalue = oldprice.replace(/,/gi, "");
priceprvalue = u.replace(/,/gi, "");
u = " " + u + "";
if (-1 != e.innerHTML.indexOf("[oldprice]")) var h = "Gi\u00e1 g\u1ed1c: ",
oldprice = "Old Price : " + oldprice + "",
p = ((parseInt(priceprvalue) - parseInt(pricevalue)) / parseInt(priceprvalue) * 100).toFixed(0) + "%";
else oldprice = h = "", p = "0%";
var o = e.innerHTML.substring(e.innerHTML.indexOf("[brief]") + 7, e.innerHTML.indexOf("[/brief]"));
var detail = e.innerHTML.substring(e.innerHTML.indexOf("[detail]") + 8, e.innerHTML.indexOf("[/detail]"));
var hotdeal = e.innerHTML.substring(e.innerHTML.indexOf("[hot]") + 5, e.innerHTML.indexOf("[/hot]"));
news = e.innerHTML.substring(e.innerHTML.indexOf("[news]") + 6, e.innerHTML.indexOf("[/news]"));
technology = -1 != e.innerHTML.indexOf("[technology]") ? e.innerHTML.substring(e.innerHTML.indexOf("[technology]") + 12, e.innerHTML.indexOf("[/technology]")) : "";
var news = -1 != e.innerHTML.indexOf("[hot]") ? e.innerHTML.substring(e.innerHTML.indexOf("[hot]") + 5, e.innerHTML.indexOf("[/hot]")) : "";
rating = -1 != e.innerHTML.indexOf("[rating]") ? e.innerHTML.substring(e.innerHTML.indexOf("[rating]") + 8, e.innerHTML.indexOf("[/rating]")) : "Updating";
desc = -1 != e.innerHTML.indexOf("[desc]") ? e.innerHTML.substring(e.innerHTML.indexOf("[desc]") + 6, e.innerHTML.indexOf("[/desc]")) : "No description";
video = -1 != e.innerHTML.indexOf("[video]") ? e.innerHTML.substring(e.innerHTML.indexOf("[video]") + 7, e.innerHTML.indexOf("[/video]")) : "Updating";
image = -1 != e.innerHTML.indexOf("[desc]") ? e.innerHTML.substring(e.innerHTML.indexOf("[image]") + 9, e.innerHTML.indexOf("[/image]")) : "No Image";
e.innerHTML = -1 != e.innerHTML.indexOf("[news]") ? '<div id="content" class="col_left"> <div class="top"> <div class="left"></div><div class="right"></div><div class="center"> <h1>' + t + '</h1> </div></div><div class="detail-new">'+ news + '</div></div>' : '<div class="prodetail-block clearfix simpleCart_shelfItem"><div class="col-1 float-l"><div class="image-prod"><div id="firstProductView"><div id="zoomer">'+hotdeal+'<a><img class="img-cc opaque" src="' + s[0].src + '"/></a></div><div class="ca-container" id="ca-container"><div class="ca-nav"><span class="ca-nav-prev">Previous</span><span class="ca-nav-next">Next</span></div><div class="ca-nav"><span class="ca-nav-prev">Previous</span><span class="ca-nav-next">Next</span></div><div class="ca-nav"><span class="ca-nav-prev">Previous</span><span class="ca-nav-next">Next</span></div><div class="ca-wrapper" style="overflow: hidden;"><div class="ca-item ca-item-1" style="left: 0px; position: absolute;"><img alt="20150627161501_mini-pc-cs918-android-tv-box-rockchip-rk3188-quad-core-02.jpg"src="' + s[1].src + '"/></div><div class="ca-item ca-item-1" style="left: 100px; position: absolute;"><img alt="20150627161501_mini-pc-cs918-android-tv-box-rockchip-rk3188-quad-core-02.jpg"src="' + s[2].src + '"/></div><div class="ca-item ca-item-1" style="left:200px; position: absolute;"><img alt="20150627161501_mini-pc-cs918-android-tv-box-rockchip-rk3188-quad-core-02.jpg"src="' + s[3].src + '"/></div><div class="ca-item ca-item-1" style="left: 300px; position: absolute;"><img alt="20150627161501_mini-pc-cs918-android-tv-box-rockchip-rk3188-quad-core-02.jpg"src="' + s[4].src + '"/></div><div class="ca-item ca-item-1" style="left: 400px; position: absolute;"><img alt="20150627161501_mini-pc-cs918-android-tv-box-rockchip-rk3188-quad-core-06.jpg"src="' + s[5].src + '"/></div></div></div></div></div></div><div class="col-2"><h1 class="title item_name" itemprop="name">' + t + '</h1><div class="prd-blk"><div class="prd-box clearfix"><div itemprop="offers" style="display: none;"></div><div class="pr-price-box "><div class="pr-new item_price">' + u +' </div><div class="pr-old">' + oldprice + '</div></div></div><div class="prd-order clearfix"><a class="item_add prd-order-bt buy-now iframe hvr-sweep-to-right" href="'+urlmuangay+'"><i class="fa fa-money" aria-hidden="true"></i>BUY NOW</a><a title="" target="_blank" href="javascript:void(0);" class="item_add prd-order-bt buy-now hvr-sweep-to-right" rel="' + r + '"><i class="fa fa-shopping-cart"></i> ADD TO CART</a><a class="product__howToBuy" href="#" target="_blank" ><i class="icn-howtobuy"></i><span class="txt-howtobuy"></span></a></div> </div><div class="sale-box"><h3 class="sale-b-ttl active" rel_data="khuyenmai"><i class="fa fa-gift"></i> Sales</h3><div class="sale-b-ct">' + o + '</div></div><div class="like-plus"> <div class="addthis_native_toolbox"></div></div></div></div> </div></div><section class="tabct-prod l-tab"><ul class="nav-tabs clearfix"> <li><a href="#tabnv-1" class="selected"><i class="fa fa-leaf"></i> Details<span> </span></a></li><li><a href="#tabnv-2" class=""><i class="fa fa-credit-card-alt" aria-hidden="true"></i> Quotations<span> </span></a></li><li><a href="#tabnv-4" class=""><i class="fa fa-file-image-o"></i> Images<span> </span></a></li><li><a href="#tabnv-7" class=""><i class="fa fa-star" aria-hidden="true"></i> Rating<span> </span></a></li></ul><div class="tab-content"><div class="tab-pane" id="tabnv-1" >' + detail + '</div><div class="tab-pane" id="tabnv-2" style="display: none;">' + technology + '</div><div class="tab-pane" id="tabnv-4" style="display: none;">'+video+'</div><div class="tab-pane" id="tabnv-7" style="display: none;">'+rating+'</div>';
}
很抱歉代码太长了:)