在JDEV 12c中使用Javascript单击时如何设置链接的样式

时间:2018-10-15 16:34:10

标签: javascript oracle-adf jdeveloper

尝试在ADF 12c中实现此目的:链接的文本最初为粗体,单击链接后,我希望文本为“正常”。代码:

<af:link ...>    <<af:clientListener method="openPdfWindowCallback( ) /> </af:link>

<af:resource type="javascript">function openPdfWindowCallback(){   
   return function(event) {
     <!-- code to open pdf window -->
     var inputComponent = event.getSource();
     inputComponent.style.fontWeight = 'normal';   } 
 }</af:resource>

这两行似乎根本不起作用:

 var inputComponent = event.getSource();
 inputComponent.style.fontWeight = 'normal';

第一行是否完全可以尝试获取链接本身?

谢谢!

1 个答案:

答案 0 :(得分:0)

这将在客户端上执行JS代码,但是由于您正在使用链接组件的动作侦听器,因此页面将重定向您。这意味着到服务器的往返行程,它将再次使用服务器上编码的样式提供页面,从而有效地消除了您更新样式的尝试。如果在开发人员工具中选中“保留日志”的情况下运行下面的代码,您将看到该代码可以工作,但会被服务器上的样式覆盖。您必须告诉服务器更改其所服务页面上的样式。

        <af:link id="l1" text="Here is a link to click"
                 inlineStyle="font-weight:bolder; margin-top:20px; margin-left:20px;">
            <af:clientListener method="openPdfWindowCallback" type="action"/>
        </af:link>
        <af:resource type="javascript">
          function openPdfWindowCallback(event) {
              // code to open pdf window 
              var inputComponent = event.getSource();
              console.log("My input component:", inputComponent);

              var elementRefernce = inputComponent.getClientId();
              console.log("my refernce:", elementRefernce);

              var myLink = document.getElementById(elementRefernce);
              console.log("My link:", myLink);

              console.log("font weight before:", myLink.style.fontWeight);
              myLink.style.fontWeight = 'normal';
              console.log("font weight after:", myLink.style.fontWeight);
          }
        </af:resource>
相关问题