日期:2014-05-17 浏览次数:21225 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <script type="text/javascript"> <!-- //判断内容时候有空行 function checkContent(content){ var pass = true; //var str = document.getElementById(textAreaId).value; var str = content; var lines = str.split('\n'); for(var i= 0; i<lines.length;i++){ var line = lines[i].replace(/\s+/g,""); if(line==""){ pass=false; break; } } return pass; } //表单提交前,检测 function onSubmit(){ var musicNames = document.getElementById("musicName").value; if(musicNames==""){ alert("音乐名称不能为空"); document.getElementById("musicName").focus(); return false; } //判断音乐名称是否有空行 if(!checkContent(musicNames)){ alert("音乐名称内有空白行"); return false; } var musicUrls = document.getElementById("musicUrl").value; if(musicUrls==""){ alert("音乐地址不能为空"); document.getElementById("musicUrl").focus(); return false; } //判断音乐url是否有空行 if(!checkContent(musicUrls)){ alert("音乐地址内有空白行"); return false; } return true; } //--> </script> </head> <body> <form method="post" action=""> <div>音乐名称</div> <div><textarea id="musicName" name="musicName" rows="3" cols="50"></textarea></div> <div>音乐地址</div> <div><textarea id="musicUrl" name="musicUrl" rows="3" cols="50"></textarea></div> <div><input type="submit" onclick="return onSubmit()" value="保存"></div> </form> </body> </html>