首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript创建的textarea在表单提交时不上传,而其它的input text可以解决方案

2012-03-04 
javascript创建的textarea在表单提交时不上传,而其它的input text可以页面中选择一个JPG文件后,JavaScript

javascript创建的textarea在表单提交时不上传,而其它的input text可以
页面中选择一个JPG文件后,JavaScript创建一组的表单项,其它的都正常,就是新产生的textarea不行,请问大家怎么解决这个问题?
页面如下:
------------------------------
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN ">

<HTML>
<HEAD>
<%@   page  
language= "java "
contentType= "text/html;   charset=GB18030 "
pageEncoding= "GB18030 "
%>
<META   http-equiv= "Content-Type "   content= "text/html;   charset=GB18030 ">
<META   name= "GENERATOR "   content= "IBM   WebSphere   Studio ">
<TITLE> test.jsp </TITLE>

</HEAD>
<BODY>

<SCRIPT   language=JavaScript>
var   photonum=1;

function   newInputFile()
{

photonum   ++;
var   ptab   =   document.getElementById( "photoTable ");
if(!ptab)   return;
var   newRow   =   ptab.insertRow(-1);
var   c1   =   newRow.insertCell(-1);
tmpStr   = "Headline <br> ";
tmpStr   += " <INPUT   type=\ "text\ "   name=\ "Headline "   +photonum   +   "\ "   size=\ "80\ "> <BR> ";
tmpStr   += "Caption <br> ";
tmpStr   +=   " <TEXTAREA   rows= '10 '   cols= '80 ' name= 'Caption "   +   photonum   +   " '> </TEXTAREA> <BR> ";
//tmpStr   +=   " <input   type= 'text '   name= 'caption '   size= '80 '> <br> ";
tmpStr   +=   "Choose   Image   File: <INPUT   type=\ "file\ "   name=\ "InputFile ";
tmpStr   +=   photonum   +   "\ "   id=\ "InputFile "   +   photonum;
tmpStr   +=     "\ "size=\ "40\ "   onchange=\ "inputFileChange( ' "   +   photonum   +   " ')\ " ";
tmpStr   +=   "> ";
c1.innerHTML   =   tmpStr;
var   c2   =   newRow.insertCell(-1);
tmpStr   =   " <IMG   border=\ "0\ "   src=\ "images/preview.jpg\ "   width=\ "283\ "   name=\ "previewImg "+   photonum;
tmpStr   +=     "\ "   id=\ "previewImg "   +   photonum+ "\ "> ";
c2.innerHTML   =   tmpStr;


}

function   inputFileChange(index_pix){

var   i   =   parseInt(index_pix,10);
var   fileName   =   document.getElementById( "InputFile "+index_pix);
if(!fileName   ||   !fileName.value)   return;
var   img   =   document.getElementById( "previewImg "+index_pix);
var   patn=   /\.jpg$|\.jpeg$/i;
if(patn.test(fileName.value)){
img.setAttribute( 'src ', 'file://localhost/ '   +   fileName.value);
if(i   ==   photonum)   newInputFile();
}   else   {
alert( "JPG   file   please ");
img.setAttribute( 'src ', 'images/preview.jpg ');
}

}

</SCRIPT>
<FORM   enctype= "multipart/form-data "   name= "uploadForm "     method= "post "   action= "/ServletUpload ">


<TABLE   border= "1 "   id= "photoTable "   align= "center ">
<TBODY>
<TR>

<TR>
<TD>
Headline <BR>
<INPUT   type= "text "   name= "Headline1 "   size= "80 "> <BR>
Caption <BR>
<TEXTAREA   rows= "10 "   cols= "80 "   name= "Caption1 "> </TEXTAREA> <BR>
Choose   Image   File:   <INPUT   type= "file "   name= "InputFile1 "   id= "InputFile1 "   size= "40 "
onchange= "inputFileChange( '1 ') ">
</TD>
<TD> <IMG   border= "0 "   src= "images/preview.jpg "   width= "283 "
name= "previewImg1 "   id= "previewImg1 "> </TD>
</TR>

<script   language= "JavaScript ">
//newInputFile();
</script>
<TR>
<TD   colspan= "2 "   align= "center "> <INPUT   type= "submit "   name= "submit "
value= "Submit "> &nbsp;   &nbsp;   &nbsp;   &nbsp;   <INPUT   type= "reset "
value= "Reset "   name= "reset "> </TD>
</TR>
</TBODY>
</TABLE>
</FORM>
</BODY>
</HTML>
--------------------------------

[解决办法]
<INPUT type= "text " name= "Headline1 " size= "80 "> <BR>
Caption <BR>
<TEXTAREA rows= "10 " cols= "80 " name= "Caption1 "> </TEXTAREA> <BR>

-- input不用闭合标签的么?
[解决办法]
如果写的不规范的话,还是把
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
这个去掉吧!
可以避免一些使用不规范的问题

热点排行