CRM:把 isv.config.xml 按钮事件移动到 entity.onload()

大家都知道在ISV.CONFIG里可以添加按钮,然后添加按钮事件,比如下面:

< Entities >
  
< Entity name = " account " >
    
< ToolBar ValidForCreate = " 0 "  ValidForUpdate = " 1 " >
      
< Button Icon = " /_imgs/ico_18_debug.gif "  PassParams = " 1 "  WinParams = ""  WinMode = " 0 "  Client = " Web "  JavaScript = " alert('Hello World!'); " >
      
< Titles >
        
< Title LCID = " 1033 "  Text = " A button "   / >
       < / Titles>
       < ToolTips >
        
< ToolTip LCID = " 1033 "  Text = " A button "   / >
       < / ToolTips>
     < / Button>
     < ToolBarSpacer  / >
     < / ToolBar>
   < / Entity>
<!--  End Custom Entities  -->
< / Entities>

 

有的时候基于维护和其他一些考虑,可以将这个按钮事件放到entity的onload()事件里(比如你有大量的JavaScript代码)。但是可能你已经注意到了,这种isv.config生成的按钮 ID 是变化的,也就是说在onload()事件里,你无法通过 document.getElementById() 方法获取这个按钮,而isv.config.xml 文件本身又不支持ID设定,所以要用到不同的方法:

for  ( var  index  in  document.getElementsByTagName( " LI " )) 
{
    
if (document.getElementsByTagName( " LI " )[index].title  ==   " A button " )
    {
        document.getElementsByTagName(
" LI " )[index].onclick  =  Button_Click;
        
break ;
    }
}

function  Button_Click()
{
    alert(
" Hello World! " );
}

 

由于按钮是附属在节点"LI"上面,所以可以先遍历找到节点 "LI",然后确定哪个节点的Title=“A button”,就是在isv.config 里 指定的 Title。就可以实现这种功能了。

你可能感兴趣的:(config)