XSL文档有一个input文本框,后面跟一个提交js按钮,怎样判断文本框内容跟上次的是否相同?
第一次加载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函数里不能用
该怎么改一下呢? JavaScript XSL XML
[解决办法]
<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保存起来