论坛首页 Web前端技术论坛

dhtmlx 扩展eXcell 实现多个超级链接

浏览 2931 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-01-25   最后修改:2009-01-25
仿照eXcell_link 实现多个超级链接
/*
muti links
多个超级链接

@author wdz123@hotmail.com
@date 2009-01-19

The corresponding  cell value in XML should be a "^" delimited list of following values:
1st - Link Text (or "img:image_src")
2nd - URL (optional)
3rd - target (optional, default is _blank)

Samples:
<cell>Stephen King</cell>
<cell>Stephen King^http://www.stephenking.com/</cell>
<cell>Stephen King^http://www.stephenking.com/^_self</cell>
<cell>text1,text2^http://news.sina.com.cn^  ^aaaa^http://news.21cn.com^</cell>
<cell>text1,text2^http://news.sina.com.cn^_self^aaaa^http://news.21cn.com^_blank</cell>
*/

function eXcell_link2(cell){
    this.cell = cell;
this.myValue = "";
    this.grid = this.cell.parentNode.grid;
this.edit = function(){}
this.getValue = function(){
if(this.cell.firstChild.getAttribute){
            if(this.myValue!=""){
return this.myValue;
}
return this.cell.firstChild.innerHTML+"^"+this.cell.firstChild.getAttribute("href")
}
else
return "";
}
this.setValue = function(val){
var flag = true;
var valsAr = val.split("^");
this.myValue = "";
      //alert('----valsAr.length===' +valsAr.length);

   if(valsAr.length==1){
   valsAr[1] = "";
   }
else{
if(valsAr.length>1){
if(valsAr.length<4){
  valsAr[1] = "href='"+valsAr[1]+"'";
}
if(valsAr.length==3)
valsAr[1]+= " target='"+valsAr[2]+"'";
else if(valsAr.length<3){
valsAr[1]+= " target='_blank'";
}
else if(valsAr.length>3){
this.myValue= val;
var i= valsAr.length % 3;
if(i>0){
                       i=1;
}
//alert('>3----valsAr.length====' +valsAr.length);
var  j= (valsAr.length  - valsAr.length % 3 )/3 + i;
var div = "";
var myTarget ="";
var  k0,k1,k2;
for(var k=1;k<= j;k++){
k0 = (k-1)*3;
k1 = (k-1)*3+1;
k2 = (k-1)*3+2;
//alert('valsAr[k2]='+valsAr[k2])

if(!valsAr[k2]){
  valsAr[k2] ="'_blank'";
}
else{            
//alert('valsAr[k2]='+valsAr[k2]+"--xxx==" +valsAr[k2].length);
valsAr[k2] = valsAr[k2].replace(/(^\s*)/g, "");
// alert('valsAr[k2]='+valsAr[k2]+"--xxx==" +valsAr[k2].length);
if(valsAr[k2]==null || valsAr[k2]=='' ||valsAr[k2]==' ' ||valsAr[k2].length<1){
valsAr[k2] ='_blank';
}
valsAr[k2] ="'" +valsAr[k2] + "'";
}
if(k>1){
div = div + "&nbsp;&nbsp;&nbsp;"
}
div = div   + "<a href='" + valsAr[k1] + "' " ;
div = div + " target=" + valsAr[k2 ] + ">" + valsAr[k0] +  " </a>"
}
                    this.setCValue(div,valsAr);
//alert('content=' + div);
flag = false;
                   // this.cell.innerHTML = '<div>'  + div +'</div>';
}
}
    }



if(flag){
  this.setCValue("<a "+valsAr[1]+" onclick='(isIE()?event:arguments[0]).cancelBubble = true;'>"+valsAr[0]+"</a>",valsAr);
}
}
}

eXcell_link2.prototype = new eXcell;
eXcell_link2.prototype.getTitle=function(){
    return this.cell.firstChild.getAttribute("href");
}



   发表时间:2009-01-25   最后修改:2009-01-25
效果图
参考附件 图片中的第4行,同事提供sina, 21cn的链接
  • 大小: 24 KB
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics