XSL文档有一个input文本框,后面跟一个提交js按钮,怎样判断文本框内容跟上次的是否相同?

xdh0817 2013-04-28 10:57:59

第一次加载XML时,给文本框内容一个初始化值,更改文本内容后点击提交按钮,Onclick函数可用getElementById获取到更改后内容,但是怎样保存上一次的值呢?

A.XML

<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type = "text/xsl" href = "A.xsl"?>
<bookstore>
<book category="children">
<title lang="en">Harry Potter</title>
<author> J K. Rowling</author>
</book>
</bookstore>


A.XSL如下:

<?xml version = "1.0" encoding = "gb2312"?>
<xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">

<xsl:template name = "HTML_HEAD">
<script type = "text/javascript" language = "javascript" src = "A.js">
var globar_str = new String("初始化值");
<![CDATA[
function OnInitialize1()
{
document.getElementsById('text-str').value =globar_str;
}
]]>
</script>
</xsl:template>

</xsl:template>
<xsl:template match = "bookstore" name ="MLIST2">
<script type = "text/javascript" language = "javascript" src = "A.js">
</script>

<form id = "form1" name = "form1" target = "_self" onsubmit = "return OnSubmitApply(this);" method = "post">
<table id = "table1" class = "content_body_area" border = "0" cellpaddng = "0" cellspacing = "0">
<tr class = "row135">
<td class = "content_value">
<input type="text" class="textbox" id="texs-tr"/>
</td>
</tr>
</table>

<table width="100%" border = "0" cellpaddng = "0" cellspacing = "0" class = "content_set" >
<input name="ApplyButton" value="提交" id="ApplyButton" type = "submit" class = "buttonX">
</input>
</table>
</form>
</xsl:template>

A.js
function func_submit(form)
{
var s = document.getElementsById('text-str').value;
if(s != globar_str )
{
globar_str = s;
}
}

存在这么几个问题:
1,第一个xsl:template HTML_HEAD 没有match,也没有其他template调用它,那么这个HTML_HEAD模版怎么实现的?
2,global_str在js函数里不能用

该怎么改一下呢?
...全文
206 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xdh0817 2013-04-29
  • 打赏
  • 举报
回复
引用 1 楼 showbo 的回复:
<script type = "text/javascript" language = "javascript" src = "A.js"> var globar_str = new String("初始化值"); <![CDATA[ function OnInitialize1() { document.getElementsById('text-str').value =globar_str; } ]]> </script> 倒入外部js后这个script不能引入js代码,要另外单独写一个没用src的script标签放置内容部js代码 <?xml version = "1.0" encoding = "gb2312"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:template match = "bookstore" name ="MLIST2"> <script type = "text/javascript" language = "javascript" src = "A.js"> </script> <script type = "text/javascript" language = "javascript"> var globar_str = new String("初始化值"); <![CDATA[ function OnInitialize1() { document.getElementsById('text-str').value =globar_str; } ]]> </script> <form id = "form1" name = "form1" target = "_self" onsubmit = "return OnSubmitApply(this);" method = "post"> <table id = "table1" class = "content_body_area" border = "0" cellpaddng = "0" cellspacing = "0"> <tr class = "row135"> <td class = "content_value"> <input type="text" class="textbox" id="texs-tr"/> </td> </tr> </table> <table width="100%" border = "0" cellpaddng = "0" cellspacing = "0" class = "content_set" > <input name="ApplyButton" value="提交" id="ApplyButton" type = "submit" class = "buttonX"> </input> </table> </form> </xsl:template> 而且提交后当前页面的globar_str会被卸载点,下一个页面获取不到,要用cookie保存起来
引用 1 楼 showbo 的回复:
<script type = "text/javascript" language = "javascript" src = "A.js"> var globar_str = new String("初始化值"); <![CDATA[ function OnInitialize1() { document.getElementsById('text-str').value =globar_str; } ]]> </script> 倒入外部js后这个script不能引入js代码,要另外单独写一个没用src的script标签放置内容部js代码 <?xml version = "1.0" encoding = "gb2312"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:template match = "bookstore" name ="MLIST2"> <script type = "text/javascript" language = "javascript" src = "A.js"> </script> <script type = "text/javascript" language = "javascript"> var globar_str = new String("初始化值"); <![CDATA[ function OnInitialize1() { document.getElementsById('text-str').value =globar_str; } ]]> </script> <form id = "form1" name = "form1" target = "_self" onsubmit = "return OnSubmitApply(this);" method = "post"> <table id = "table1" class = "content_body_area" border = "0" cellpaddng = "0" cellspacing = "0"> <tr class = "row135"> <td class = "content_value"> <input type="text" class="textbox" id="texs-tr"/> </td> </tr> </table> <table width="100%" border = "0" cellpaddng = "0" cellspacing = "0" class = "content_set" > <input name="ApplyButton" value="提交" id="ApplyButton" type = "submit" class = "buttonX"> </input> </table> </form> </xsl:template> 而且提交后当前页面的globar_str会被卸载点,下一个页面获取不到,要用cookie保存起来
恩恩,按照你说的,在template MLIST2中加入不带src的script就可以了~~ 但是有个问题,别人是这样实现的: A.xsl <?xml version = "1.0" encoding = "gb2312"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:template name = "HTML_HEAD"> <script type = "text/javascript" language = "javascript"> var globar_str = new String("初始化值"); <![CDATA[ function OnInitialize1() { document.getElementsById('text-str').value =globar_str; } ]]> </script> </xsl:template> </xsl:template> <xsl:template match = "bookstore" name ="MLIST2"> <script type = "text/javascript" language = "javascript" src = "A.js"> </script> <form id = "form1" name = "form1" target = "_self" onsubmit = "return OnSubmitApply(this);" method = "post"> <table id = "table1" class = "content_body_area" border = "0" cellpaddng = "0" cellspacing = "0"> <tr class = "row135"> <td class = "content_value"> <input type="text" class="textbox" id="texs-tr"/> </td> </tr> </table> <table width="100%" border = "0" cellpaddng = "0" cellspacing = "0" class = "content_set" > <input name="ApplyButton" value="提交" id="ApplyButton" type = "submit" class = "buttonX"> </input> <input name ="CancleButton" value = "取消" id = "CancleButton" type = "button" class = "buttonX" onclick = "OnCancleButton()"/> </table> </form> </xsl:template> </xsl:stylesheet> 这里先不请教您cookie的问题~我想问的是它是怎么实现的?什么时候会调用xsl模版HTML_HEAD呢? 背景说明:以上这些东西源自于一项工作,本来有一个页面,页面分为两部分:左边显示一个树形结构菜单, 点击菜单中的某个选项可以在右边显示相应的页面,类似我的电脑中查看文件夹。 我要在左边的菜单里增加一个“姓名”选项,点击这个选项之后,就会在右边出现一个页面,即本帖所发的xml + xsl +js文档。有一个文本框,一个提交按钮,一个取消按钮,点击提交按钮,用js函数判断提交的姓名是否与上次的相同,如果不同就设置为新值,并使用ajax向服务器发set请求。
Go 旅城通票 2013-04-29
  • 打赏
  • 举报
回复
<script type = "text/javascript" language = "javascript" src = "A.js"> var globar_str = new String("初始化值"); <![CDATA[ function OnInitialize1() { document.getElementsById('text-str').value =globar_str; } ]]> </script> 倒入外部js后这个script不能引入js代码,要另外单独写一个没用src的script标签放置内容部js代码 <?xml version = "1.0" encoding = "gb2312"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:template match = "bookstore" name ="MLIST2"> <script type = "text/javascript" language = "javascript" src = "A.js"> </script> <script type = "text/javascript" language = "javascript"> var globar_str = new String("初始化值"); <![CDATA[ function OnInitialize1() { document.getElementsById('text-str').value =globar_str; } ]]> </script> <form id = "form1" name = "form1" target = "_self" onsubmit = "return OnSubmitApply(this);" method = "post"> <table id = "table1" class = "content_body_area" border = "0" cellpaddng = "0" cellspacing = "0"> <tr class = "row135"> <td class = "content_value"> <input type="text" class="textbox" id="texs-tr"/> </td> </tr> </table> <table width="100%" border = "0" cellpaddng = "0" cellspacing = "0" class = "content_set" > <input name="ApplyButton" value="提交" id="ApplyButton" type = "submit" class = "buttonX"> </input> </table> </form> </xsl:template> 而且提交后当前页面的globar_str会被卸载点,下一个页面获取不到,要用cookie保存起来

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧