行值在javascript中不可用
在参考了以下两个参考之后,我在行值在javascript中不可用,javascript,asp.net,xslt,xslt-1.0,Javascript,Asp.net,Xslt,Xslt 1.0,在参考了以下两个参考之后,我在XSLtemplate中创建了一个javascript函数。javascript正在被调用,并出现警报。但是CountID的值在警报中是空的,尽管它在html中有值 我们需要做什么更改来提醒CountID 注意:这是一个ASP.Net项目,我使用的是VisualStudio2005 注意:这是一个已有的项目,我是XSLT新手(尽管我对javascript、xml、kendoui、html5等有一定的了解) 参考资料 Javascript <SCRI
XSL
template中创建了一个javascript函数。javascript正在被调用,并出现警报。但是CountID的值在警报中是空的,尽管它在html中有值
我们需要做什么更改来提醒CountID
注意:这是一个ASP.Net项目,我使用的是VisualStudio2005
注意:这是一个已有的项目,我是XSLT新手(尽管我对javascript、xml、kendoui、html5等有一定的了解)
参考资料
Javascript
<SCRIPT LANGUAGE="javascript" DEFER="true">
var myVar = "<xsl:value-of select="CountID"/>";
<xsl:comment>
function on_change()
{
alert(myVar);
}
</xsl:comment>
</SCRIPT>
<?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"> </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>
var myVar=“”;
_change()上的函数
{
预警(myVar);
}
源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>
34rrgt56
01
圆周率
操作
N
李子C
05/09/2014 00:19:04
注意:这个XML被传递到一个自定义控件,它在该控件中进行更多的添加。但是对于这个问题,这个xml应该足够了
完整的XSL样式表
<SCRIPT LANGUAGE="javascript" DEFER="true">
var myVar = "<xsl:value-of select="CountID"/>";
<xsl:comment>
function on_change()
{
alert(myVar);
}
</xsl:comment>
</SCRIPT>
<?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"> </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>
var myVar=“”;
_change()上的函数
{
预警(myVar);
}
关于(u change)
总结
最后一个错误:
一行
submitForm(this,this.form“”)
window.row.style['display']='none';style['display']='none';
在我看来,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>
关于(u change)
总结
与
然后让Javascript函数接受一个参数,而不是
var myVar = "<xsl:value-of select="CountID"/>";
<xsl:comment>
function on_change()
{
alert(myVar);
}
</xsl:comment>
var myVar=”“;
_change()上的函数
{
预警(myVar);
}
简单使用
<script type="text/javascript">
function on_change(id) {
alert(id);
}
</script>
更改时的功能(id){
警报(id);
}
这就是所需要的。您需要显示输入XML,除非它有一个名为
CountID
的根元素执行var myVar=”“代码>只分配一个空字符串。您的其他表达式如
表明根元素名为root
@MartinHonnen我从现有代码中复制了这行代码,正如您在
中看到的那样。如果您有一个匹配/
的模板,那么
将选择一个名为CountID
的根元素。如果没有这样的元素,则输出一个空字符串。因此,您需要确保使用路径选择嵌套级别的元素,例如,
将选择输入中任何级别的第一个CountID
元素或select=“/ROOT/CountID”
将选择名为root
@MartinHonnen的根元素的名为CountID
的子元素。感谢我使用select=“//CountID”/>”
它正在工作。但我想这会给我错误的结果