行值不是在JavaScript中使用(Row value is not available in j

2019-10-20 03:09发布

指以下两个引用后,我已经创造了一个JavaScript函数XSL模板。 JavaScript的获取调用和警报的出现。 但CountID的值在警告,虽然它在HTML值来为空。

做什么改变,我们需要做的,提醒CountID?

注:这是一个ASP.Net项目中,我使用Visual Studio 2005注:这是一个现有的项目,我是新来的XSLT(虽然我对JavaScript的,XML知识,kendoui,HTML5等)

参考

  1. 如何将在XSL文件客户端脚本函数

  2. 在XSLT传递参数的JavaScript脚本

使用Javascript

    <SCRIPT LANGUAGE="javascript" DEFER="true">

        var myVar = "<xsl:value-of select="CountID"/>";
        <xsl:comment>
            function on_change()
            {
                alert(myVar);
            }
        </xsl:comment>

</SCRIPT>

XML源代码

<ROOT>
    <Counts>
        <CountID>34rrgt56</CountID>
        <PlantCD>01</PlantCD>
        <CountType>PI</CountType>
        <StatusCD>OP</StatusCD>
        <EntryCompleteIND>N</EntryCompleteIND>
        <StartedBy>Lijo C</StartedBy>
        <CreatedOnDate>05/09/2014 00:19:04</CreatedOnDate>
    </Counts>
</ROOT>

注:该XML传递给它做一些更多的添加自定义的控制。 然而,对于这个问题,这XML应该够了。

完整的XSL样式表

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" indent="yes"/>
    <xsl:template match="/">

        <SCRIPT LANGUAGE="javascript" DEFER="true">

            var myVar = "<xsl:value-of select="CountID"/>";
            <xsl:comment>
                function on_change()
                {
                    alert(myVar);
                }
            </xsl:comment>

        </SCRIPT>


        <div>

            <TABLE border="0" cellPadding="0" cellSpacing="0" BGCOLOR="#E5DBE2" width="100%">
                <TR>
                    <TD CLASS="Heading3" ALIGN="LEFT" WIDTH="25%">
                        <xsl:value-of select="/ROOT/Labels/PhysicalInventoryIDText/." />
                    </TD>
                    <TD CLASS="Heading3" ALIGN="LEFT" WIDTH="20%">
                        <xsl:value-of select="/ROOT/Labels/DateTimeText/." />
                        <BR/>
                        <xsl:value-of select="ROOT/Labels/StartedText/." />
                    </TD>
                    <TD CLASS="Heading3" ALIGN="LEFT" WIDTH="15%"></TD>
                </TR>
            </TABLE>


            <TABLE style="display:none" name="emailTable"  id="emailTable" width="100%" BGCOLOR="#E5DBE2">
                <TR>
                    <TD width="25%" CLASS="Normal" colspan="1"  ALIGN="RIGHT">
                        <B>
                            <xsl:value-of select="/ROOT/Labels/EmailAddressText/." />
                        </B>
                    </TD>
                    <TD width="75%" ALIGN="LEFT">
                        <img src="../Images/ArrowInvisible.gif" width="15" height="13" name="imgEmail1" />
                        <INPUT id="txtEmail1" name="txtEmail1" runat="server" width="100px" maxlength="100" Required="true" onfocus="document.forms[0].imgEmail1.src='../Images/ArrowVisibleDB.gif';" onblur="document.forms[0].imgEmail1.src='../Images/ArrowInvisible.gif';" />
                    </TD>
                </TR>
                <TR>
                    <TD width="25%" CLASS="Normal" colspan="1" ALIGN="RIGHT">
                        <B>
                            <xsl:value-of select="/ROOT/Labels/EmailAddressText/." />
                        </B>
                    </TD>
                    <TD width="75%" ALIGN="LEFT">
                        <img src="../Images/ArrowInvisible.gif" width="15" height="13" name="imgEmail2" />
                        <INPUT id="txtEmail2" name="txtEmail2" runat="server" width="100px" maxlength="100" Required="true" onfocus="document.forms[0].imgEmail2.src='../Images/ArrowVisibleDB.gif';" onblur="document.forms[0].imgEmail2.src='../Images/ArrowInvisible.gif';" />
                    </TD>
                </TR>
            </TABLE>

            <TABLE border="0" cellPadding="0" cellSpacing="0" BGCOLOR="#E5DBE2" width="100%">
                <xsl:for-each select="ROOT/Counts">
                    <TR>
                        <TD CLASS="Normal" ALIGN="LEFT" width="25%">
                            <xsl:value-of select="CountID"/>
                        </TD>


                        <TD CLASS="Normal" ALIGN="LEFT" width="20%" style="font-size:12">
                            <xsl:value-of select="CreatedOnDate"/>
                        </TD>

                        <TD ALIGN="RIGHT" width="15%">
                            <Input type="button">
                                <xsl:attribute name="id">
                                    <xsl:value-of select="CountID"/>
                                </xsl:attribute>
                                <xsl:attribute name="name">
                                    <xsl:value-of select="CountID"/>
                                </xsl:attribute>

                                <xsl:attribute name="onclick">
                                    <xsl:text>on_change()</xsl:text>
                                </xsl:attribute>

                                <xsl:attribute name="value">Conclude</xsl:attribute>
                            </Input>
                        </TD>

                    </TR>
                    <xsl:if test="LastError!=''">
                        <TR>
                            <TD COLSPAN="3" CLASS="Normal" ALIGN="LEFT" width="100%">
                                Last Error:  <xsl:value-of select="LastError"/>
                            </TD>
                        </TR>
                    </xsl:if>
                    <TR style="display:none">
                        <xsl:attribute name="id">
                            row<xsl:value-of select="CountID" />
                        </xsl:attribute>
                        <TD class="NormalError" colspan="4">
                            <xsl:value-of select="/ROOT/Labels/PIConcludeWarning/." />
                            <Input type="button" >
                                <xsl:attribute name="value">
                                    <xsl:value-of select="/ROOT/Labels/YesText/." />
                                </xsl:attribute>
                                <xsl:attribute name="onclick">
                                    submitForm(this,this.form,'<xsl:value-of select="CountID"/>')
                                </xsl:attribute>
                            </Input>
                            <xsl:text disable-output-escaping="yes">&#160;</xsl:text>
                            <Input type="button" >
                                <xsl:attribute name="value">
                                    <xsl:value-of select="/ROOT/Labels/CancelText/." />
                                </xsl:attribute>
                                <xsl:attribute name="onclick">
                                    window.row<xsl:value-of select="CountID" />.style['display'] = 'none';window.emailTable.style['display'] = 'none';
                                </xsl:attribute>
                            </Input>
                        </TD>
                    </TR>

                    <TR HEIGHT="1">
                        <TD BGCOLOR="#FFFFFF" COLSPAN="6" height="1">
                            <NOBR/>
                        </TD>
                    </TR>
                </xsl:for-each>
            </TABLE>
        </div>
    </xsl:template>
</xsl:stylesheet>

Answer 1:

在我看来XSLT编码方面的正确方法是编写模板基于XSLT的代码,但你有一个模板替换做这一切的开始

                        <Input type="button">
                            <xsl:attribute name="id">
                                <xsl:value-of select="CountID"/>
                            </xsl:attribute>
                            <xsl:attribute name="name">
                                <xsl:value-of select="CountID"/>
                            </xsl:attribute>

                            <xsl:attribute name="onclick">
                                <xsl:text>on_change()</xsl:text>
                            </xsl:attribute>

                            <xsl:attribute name="value">Conclude</xsl:attribute>
                        </Input>

<input type="button" id="{CountID}" name="{CountID}" onclick="on_change(this.id);" value="Conclude"/>

然后使JavaScript函数带一个参数,而不是这样的

    var myVar = "<xsl:value-of select="CountID"/>";
    <xsl:comment>
        function on_change()
        {
            alert(myVar);
        }
    </xsl:comment>

只需使用

<script type="text/javascript">
function on_change(id) {
  alert(id);
}
</script>

这就是所有需要的。



文章来源: Row value is not available in javascript