代码之家  ›  专栏  ›  技术社区  ›  Matthew Vines

如何在html属性中的javascript内插入带有属性的XSLT元素?

  •  0
  • Matthew Vines  · 技术社区  · 14 年前

    下面是我试图为Gizmox WebGUI DataGrid控件修改的主题文档的简化版本。我遇到的问题是button元素上可怕的onclick事件属性。我已经用这种方法试过了,而且 &quot; 代替 " 对于属性引号。在这两种情况下,文档都不会生效。我可以在javascript方法中做一些工作,可能在我完成之前会做,但是我仍然需要传递 <xsl:value-of select="@Attr.TotalPages"/> 在这种情况下也是一个参数。

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:WC="wgcontrols">
        <xsl:template name="tplListDrawPaging">
        <table border="0" cellpadding="0" cellspacing="0" class="List-PagingPanel" dir="{$dir}" align="center">
          <tr>
              <td width="150px" align="right" class="Common-FontData" dir="ltr">
                  <span>Go to page:</span>
                  <input type="text" id="{@Id}-goToPageTextBox" name="{@Id}-goToPageTextBox" style="width:35px;" />
                  <button type="button" onclick="var goToValue = getElementById('{@Id}-goToPageTextBox').value;
                                            if(goToValue &lt;= 0){goToValue = 1;}
                                            else if(goToValue &gt; <xsl:value-of select="@Attr.TotalPages"/>){goToValue = <xsl:value-of select="@Attr.TotalPages"/>;})
                                            List_NavigateTo('{@Id}',goToValue);">Go</button>
            </td>
          </tr>
        </table>
      </xsl:template>
    </xsl:stylesheet>
    
    1 回复  |  直到 14 年前
        1
  •  3
  •   Frédéric Hamidi    14 年前

    你必须 escape the curly braces

    <button type="button" onclick="var goToValue = document.getElementById('{@Id}-goToPageTextBox').value; if (goToValue &lt;= 0) {{ goToValue = 1; }} else if (goToValue &gt; {@Attr.TotalPages}) {{ goToValue = {@Attr.TotalPages}; }} List_NavigateTo('{@Id}', goToValue);">Go</button>
    

    我肯定会把代码放在它自己的函数中,然后从 onclick 不过,汉德勒。