dynamic url

by bvotcode

JavaScript

function updateLinkindynamicURL_with_highlight(link, old, newVal, highlight) {
    // Kiểm tra điều kiện highlight và thêm class nếu cần
    if (/^(yes|highlight)$/i.test(highlight)) {
        // Nếu đã có thẻ <a ... thì chèn class vào trước dấu '>'
        link = link.replace(/(<a\s+[^>]*)(>)/i, function(match, p1, p2) {
            // Nếu đã có attribute class thì không thêm nữa
            return /class=/.test(p1) 
                ? match 
                : p1 + ' class="childtabSelected"' + p2;
        });
    }
    
    // Định dạng lại link (nếu cần)
    var link_format = link.replace(/="\s+/g, '="').replace(/=0\s+/g, '=0');
    var link_new = link_format.replace(old, newVal);
    
    return link_new;
}
var screen_link = '<a href=" danh_sach_flow_va_data_dashboard_internal_view_quan_ly?loginname=0&project=0&company=0&department=0&phase=0&integration=0&source=0&target=0&status=0 ">'
var output = ''+updateLinkindynamicURL_with_highlight(screen_link,"status=0","status=all","highlight")+'Cần làm</a>'
alert(output)