JS中也可以使用JSTL和EL標簽


//往上滑是調用分頁
        function Ajax(currPage, pageSize) { // ajax后台交互String currPage,String pageSize
            var el, Plist, i;
            el = document.getElementById('thelist');
            var cancle = function(options) {
                var pattern = '${pageContext.request.contextPath}/integralParadise/userIntegralRecordsPaging?currPage=:currPage&pageSize=:pageSize';
                for ( var key in options) {
                    pattern = pattern.replace(':' + key, options[key] || '');
                }
                return pattern;
            }

            $.post(cancle({
                currPage : currPage,
                pageSize : pageSize
            }), function(result) {
                var integralRecord = result.page;
                if (integralRecord.length > 0) {
                    $("#currPage").val(result.currPage + 1);
                    $("#pageSize").val(result.pageSize);
                    //追加信息
                    var divItem = "";
                    $.each(integralRecord, function(index, detail) {
                        if(detail.integral != 0){
                            var type = detail.typeId;
                            var integral = detail.integral;
                            var now = new Date(detail.operatorTime); 
                            var time = now.Format("yyyy-MM-dd");
                            var positiveOrNegative =detail.positiveOrNegative ;
                            var operation  = detail.operation;
                            var money = parseInt(detail.money);
                            var rate = detail.rate;
                            var name;
                            switch (type)
                                {
                                case 1:
                                  name="賬號綁定獎勵";
                                  break;
                                case 2:
                                  name="出借獎勵";
                                  break;                                
                                }
                            divItem += "<div class='dtb_item'><div class='dtb_l'><h3>" +name+ "</h3><p>"+time+"</p></div><div class='dtb_m'>";
                            if(type == 11){
                                divItem +="<p class='i_msg purple'>" +"+"+integral+"</p></div></div>";
                            }else if(positiveOrNegative == false){
                                divItem +="<p class='i_msg green'>" +"-"+integral+"</p></div></div>";
                            }else{
                                divItem +="<p class='i_msg red'>" +"+"+integral+"</p></div></div>";
                            }                            
                        }
                    });                
                    $("#thelist").append(divItem);
                    $(".pullUpLabel").html("")
                    myScroll.refresh();
                } else {
                    $('.pullUpLabel').html('沒有更多記錄');
                    <c:if test="${showmessage <= 0 }">$("#dateTip").html("2016年9月7日前的記錄暫時無法顯示");</c:if>
                }
            });
        }

這段代碼最后用了JSTL和EL,但是這個段JS是在JSP頁面中,如果JS不在JSP中要再JS設定使用該JS的JSP頁面。

也就是說服務器端把JSTL和EL的值先轉化后傳到JS中,JS已經得到了靜態的值來執行。

 <c:if test="${showmessage <= 0 }">$("#dateTip").html("2016年9月7日前的記錄暫時無法顯示");</c:if>

獲取EL的值

var result = "${showmessage}"; 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM