当前位置: 代码迷 >> Web前端 >> textarea在xsl中的bug及其解决方法
  详细解决方案

textarea在xsl中的bug及其解决方法

热度:139   发布时间:2012-10-26 10:30:59.0
textarea在xsl中的bug及其解决办法

xls的一些问题。 出现这些问题的原因不清楚,把一些解决的办法记在这里吧。

?

今天做了一个类似于 csdn论坛用xml+xslt生成贴子 的留言本(asp),发现在xml分析器把xslt转换成相应该的html时,如果标鉴是TextArea(如:<textarea? id="postContent" name="postContent"></textarea>)时,xml解析器会将这个TextArea转换成<textarea? id="postContent" name="postContent"/>,因为<textArea>中没有内容,所以就把段html简写了.但是这样简写以后,asp服务器端程序就无法得到id为postContent的TextArea的内容了。
后来google了一下,找到了一个比较无奈的解决方案,就是在TextArea标签之间加一个XSL:Text空白串。
<textarea? id="postContent" name="postContent"><xsl:text> </xsl:text></textarea>
顺便提醒一句,xsl:text在有些名称空间中没有,不过在http://www.w3.org/1999/XSL/Transform中肯定有的.

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zjsen/archive/2004/12/25/229187.aspx

?

?

?

<textarea cols="90" rows="3" >
????????<xsl:attribute name="name">answerInfoID</xsl:attribute><xsl:text></xsl:text>
????????<xsl:attribute name="id">answerInfoID</xsl:attribute><xsl:text></xsl:text>
</textarea>

主意:以上语句是解决了textarea的问题,但是也产生了另外一个问题,就是用js根据name属性去取textarea,是取不到的。 如以下语句,他总是返回了 undefined

$("#answerInfoID").val();

?

解决的办法,是把第一个><xsl:text></xsl:text>去掉。 如下的写法:

<textarea cols="90" rows="3" >
????????<xsl:attribute name="name">answerInfoID</xsl:attribute>
????????<xsl:attribute name="id">answerInfoID</xsl:attribute><xsl:text></xsl:text>
</textarea>

这样才算圆满的解决了问题。

?

另外呢,还有一个问题

<div? >?答题区:
?????? <xsl:attribute name="name">answerInfoDiv</xsl:attribute>
</div>

如果这样写的话, 在js去取这个div的话,也是取不到的。如: $("div[name*='answerInfoDiv']").hide();

?

要把问题写在xsl后面才可以,如下:

<div? >

?????? <xsl:attribute name="name">answerInfoDiv</xsl:attribute>?答题区:
</div>

?

  相关解决方案