通过页面元素获取值、js判空、字符串转为数字及页面设置唯一ID

        <ul class="floorOne">
            #set($groupRespDTOList = '') ##属性组
            #if($!{pagePub})
                #set($groupRespDTOList=$crossItem.cmsItemGdsfloorPubRespDTOList)
            #else
                #set($groupRespDTOList=$crossItem.cmsItemGdsfloorPreRespDTOList)
            #end
            #foreach($cmsItemGds in $groupRespDTOList)
                #if($cmsItemGds.gdsId && $cmsItemGds.gdsId != '')
                    #set($detailUrl="gdsdetail/"+$cmsItemGds.gdsId+"-")
                    <li goodsId="$!{cmsItemGds.gdsId}" promId="">
                        <input style="display: none;" type="text" id="mainTitle$!{cmsItemGds.gdsId}" value="$!{mainTitle}"/>
                        <input style="display: none;" type="text" id="subTitle$!{cmsItemGds.gdsId}" value="$!{subTitle}"/>
                        <input style="display: none;" type="text" id="newButtonWord$!{cmsItemGds.gdsId}" value="$!{buttonWord}"/>
                        <div class="itemBox">
                            <p class="tipImg lt"><img id="left_Tag_image" src="#genImageUrl($!{picUrl1},'')" alt=""></p>
                            <p class="tipImg rt"><img id="right_Tag_image" src="#genImageUrl($!{picUrl2},'')" alt=""></p>
                            <a href="javascript:void(0);" lazy-href="$!{detailUrl}">
                            <img id="gdsImg" name="imgName" class="prodImg" src="#genImageUrl($!{cmsItemGds.gdsUrl},'')" alt="">
                            </a>
                        #*<img src="../images/pro/list-pro04.png" alt="">*#
                            <div class="product">
                                <h3 name="gdsName"></h3>
                                <p class="word"  name="secondName"></p>
                                <p class="price" name="newPrice1" style="text-align:left"></p>
                                <!--<p class="word" style="text-decoration: line-through;text-align:left" name="oldPrice"></p>-->
                            </div>
                        </div>
                    </li>
                #end
            #end
        </ul>
return new Promise(function (resolve) {
                    var $li = $(li);
             //通过页面元素的id、name、class等获取值 $li.attr(
'loaded', '1'); var siteId = $('#siteId').val(); var goodsId = $li.attr("goodsId"); var promId = $li.attr("promId"); var $img = $li.find('img[name=imgName]'); var $gdsName = $li.find('h3[name=gdsName]'); var $secondName= $li.find('p[name=secondName]'); var $newPrice = $li.find('span[name=newPrice]'); var $newPrice1 = $li.find('p[name=newPrice1]'); var $oldPrice = $li.find('p[name=oldPrice]'); var $aLink = $li.find('a.link'); var $upperLeftMark = $li.find("#upperLeftMark"); var $DBword = $li.find("#DBword"); // var $aCarbtn = $li.find('a.carBtn'); var callBack = function (gdsInfo) { if (gdsInfo && gdsInfo.respDTO) { $($img).attr('src', gdsInfo.respDTO.mainPic.url); var mainTitle=gdsInfo.respDTO.gdsName;
                //通过商品ID+字符串组装成页面的元素Id,以取得相应的值
var mainTitleId="mainTitle"+goodsId; var newMainTitle=$("#"+mainTitleId).val(); if(''!=newMainTitle && typeof(newMainTitle) != 'undefined' && newMainTitle.length>0 ){ mainTitle=newMainTitle; } $($gdsName).html('' + mainTitle + ''); var subTitle=''; if(gdsInfo.respDTO.gdsSubHead){ subTitle=gdsInfo.respDTO.gdsSubHead; } var subTitleId="subTitle"+goodsId; var newSubTitle=$("#"+subTitleId).val();
                  //获取页面元素值后判空:
if(''!=newSubTitle && typeof(newSubTitle) != 'undefined' && newSubTitle.length>0 ){ subTitle=newSubTitle; } $($secondName).html('' + subTitle + ''); // $('#oldPrice',$(this)).addClass('prc-del'); if (opts.isPub) { //已发布 $($aLink).attr('href', gdsInfo.respDTO.url); // $($aCarbtn).attr('href',gdsInfo.respDTO.url); } if ('02' == gdsInfo.respDTO.sourceType) { } else {
                  //将字符串转换为数字,再四舍五入保留N位小数点
var newPrice = parseFloat(gdsInfo.respDTO.skuInfo.discountPrice / 100).toFixed(0); $($newPrice).html('<em class="yuan">¥</em>' + newPrice); var buttonWord = "抢购"; var buttonWordId="newButtonWord"+goodsId; var newButtonWord=$("#"+buttonWordId).val(); if(''!=newButtonWord && newButtonWord.length>0 ){ buttonWord=newButtonWord; } var linkUrl= "gdsdetail/"+goodsId+"-" ; var ordPrice= parseFloat(gdsInfo.respDTO.skuInfo.guidePrice / 100).toFixed(0); $($oldPrice).html('<small class="small">原价:¥'+ ordPrice+'</small>'); $($newPrice1).html('<strong>¥'+ newPrice +'<small>起</small></strong><small class="small">原价:¥'+ordPrice+'</small><a href="javascript:void(0);" ' + 'id="linkBottonId" lazy-href="'+linkUrl+'">'+buttonWord+'</a>'); } } resolve(); } });

猜你喜欢

转载自www.cnblogs.com/xuhk1819/p/12933560.html
今日推荐