Html 在XSLT中,如何用空格填充文本字段?
我有一个包含三个字段的表,如下所示:Html 在XSLT中,如何用空格填充文本字段?,html,xml,xslt,padding,spacing,Html,Xml,Xslt,Padding,Spacing,我有一个包含三个字段的表,如下所示: <table cellpadding="0" cellspacing="0" class="innerBodyColor"> <tr> <th style="width:303px"><label class="Label" for="First">First:</label></th> <th style="width:181px">
<table cellpadding="0" cellspacing="0" class="innerBodyColor">
<tr>
<th style="width:303px"><label class="Label" for="First">First:</label></th>
<th style="width:181px"><label class="Label" for="Second">Second:</label></th>
<th style="width:117px"><label class="Label" for="Third">Third:</label></th>
</tr>
<tr>
<td style="padding-right: 5 px">
<xsl:call-template name="text">
<xsl:with-param name="name" select="'First'"/>
<xsl:with-param name="fontSize" select="'Large'"/>
<xsl:with-param name="editType" select="'AlphanumericSC'"/>
<xsl:with-param name="maxLength" select="'16'"/>
<xsl:with-param name="width" select="'303'"/>
<xsl:with-param name="onValueChange">handleValueChange(); setHidden(); padSpaces(); </xsl:with-param>
</xsl:call-template>
</td>
<td style="padding-right: 5 px">
<xsl:call-template name="text">
<xsl:with-param name="name" select="'Second'"/>
<xsl:with-param name="fontSize" select="'Large'"/>
<xsl:with-param name="editType" select="'AlphanumericSC'"/>
<xsl:with-param name="maxLength" select="'12'"/>
<xsl:with-param name="width" select="'181'"/>
<xsl:with-param name="onValueChange">padSpaces(); </xsl:with-param>
</xsl:call-template>
</td>
<td style="">
<xsl:call-template name="text">
<xsl:with-param name="name" select="'Third'"/>
<xsl:with-param name="fontSize" select="'Large'"/>
<xsl:with-param name="editType" select="'AlphanumericSC'"/>
<xsl:with-param name="maxLength" select="'10'"/>
<xsl:with-param name="width" select="'117'"/>
<xsl:with-param name="onValueChange">padSpaces(); </xsl:with-param>
</xsl:call-template>
</td>
</tr>
</table>
function padSpaces()
{
var first = getValueById('First').replace(/\s/g, '');
var second = getValueById('Second');
var third = getValueById('Third');
while (first.length < 16)
{
first += " ";
}
setValueById('First', first)
}
第一:
第二:
第三:
handleValueChange();setHidden();padspace();
padspace();
padspace();
我使用函数padspace()尝试用给定数量的空格填充每个字段
该函数如下所示:
<table cellpadding="0" cellspacing="0" class="innerBodyColor">
<tr>
<th style="width:303px"><label class="Label" for="First">First:</label></th>
<th style="width:181px"><label class="Label" for="Second">Second:</label></th>
<th style="width:117px"><label class="Label" for="Third">Third:</label></th>
</tr>
<tr>
<td style="padding-right: 5 px">
<xsl:call-template name="text">
<xsl:with-param name="name" select="'First'"/>
<xsl:with-param name="fontSize" select="'Large'"/>
<xsl:with-param name="editType" select="'AlphanumericSC'"/>
<xsl:with-param name="maxLength" select="'16'"/>
<xsl:with-param name="width" select="'303'"/>
<xsl:with-param name="onValueChange">handleValueChange(); setHidden(); padSpaces(); </xsl:with-param>
</xsl:call-template>
</td>
<td style="padding-right: 5 px">
<xsl:call-template name="text">
<xsl:with-param name="name" select="'Second'"/>
<xsl:with-param name="fontSize" select="'Large'"/>
<xsl:with-param name="editType" select="'AlphanumericSC'"/>
<xsl:with-param name="maxLength" select="'12'"/>
<xsl:with-param name="width" select="'181'"/>
<xsl:with-param name="onValueChange">padSpaces(); </xsl:with-param>
</xsl:call-template>
</td>
<td style="">
<xsl:call-template name="text">
<xsl:with-param name="name" select="'Third'"/>
<xsl:with-param name="fontSize" select="'Large'"/>
<xsl:with-param name="editType" select="'AlphanumericSC'"/>
<xsl:with-param name="maxLength" select="'10'"/>
<xsl:with-param name="width" select="'117'"/>
<xsl:with-param name="onValueChange">padSpaces(); </xsl:with-param>
</xsl:call-template>
</td>
</tr>
</table>
function padSpaces()
{
var first = getValueById('First').replace(/\s/g, '');
var second = getValueById('Second');
var third = getValueById('Third');
while (first.length < 16)
{
first += " ";
}
setValueById('First', first)
}
函数padspace()
{
var first=getValueById('first')。替换(/\s/g');
var second=getValueById('second');
var third=getValueById('third');
while(第一个长度<16)
{
第一个+=”;
}
setValueById('First',First)
}
这在某种程度上是可行的。事实上,它确实会将第一个字段填充为16个字符,但这会使处理该字段变得困难,因为每次修改该字段时都会添加必要的空白(以达到其最大长度16)。这可能是因为代码是“onValueChange”执行的,而不是用户在字段中输入完数据后执行的
是否有:
1) 在字段中填充空格而不调用函数的其他方法;或
2) 执行函数的其他方法,而不是每次字段值更改时都执行?我看不出这与XSLT有什么关系,问题似乎出在javascript上。第二点,为什么你需要垫它?如果是为了布局,HTML/CSS有更好的方法。如果是因为流程的后续部分需要填充,请在处理之前填充它;我建议编辑这个问题,以显示结果HTML
input
元素,而不是XSLT模板,并将[XSLT]标记替换为[javascript]。