function checkEmail(mail)
{
if(mail.value!="")
{
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail.value))
{
return;
}
alert("E-mail不正確");
mail.value="";
}
}
2015年3月25日 星期三
jQuery : 判斷radio有無選取 (check radio type is checked)
html
<input id="labt1" type="radio" name="LABTYPE" name="LAB" value="1" >LAB1
<input id="labt2" type="radio" name="LABTYPE" name="LAB" value="2" >LAB2
--------------------------------------------
JavaScript
if(typeof($("input[name=LABTYPE]:checked").val()) === "undefined" )
{
alert("請選擇LAB");
return false;
}
<input id="labt1" type="radio" name="LABTYPE" name="LAB" value="1" >LAB1
<input id="labt2" type="radio" name="LABTYPE" name="LAB" value="2" >LAB2
--------------------------------------------
JavaScript
if(typeof($("input[name=LABTYPE]:checked").val()) === "undefined" )
{
alert("請選擇LAB");
return false;
}
jQuery : 判斷html text不可空白 (check html input tag value not null)
html
<form id="FROMTAG" name="form1" method="post">
<input type="text">
----------------------------------------------------------------
JavaScript
$("#FROMTAG").find(':input').each(function()
{
var ty = this.type;
var val = $(this).val();
if(ty=="text" && val=="")
{
alert("欄位不可空白");
return false;
}
});
<form id="FROMTAG" name="form1" method="post">
<input type="text">
----------------------------------------------------------------
JavaScript
$("#FROMTAG").find(':input').each(function()
{
var ty = this.type;
var val = $(this).val();
if(ty=="text" && val=="")
{
alert("欄位不可空白");
return false;
}
});
2015年3月24日 星期二
jQuery : Ajax html
var div
var organ
$.ajax({
url: '/html/text/pages/Mean.jsp',
dataType: 'html',
type:'POST',
async:false,
data: { No: div, Size: organ },
error: function(xhr) {
alert('Ajax request 發生錯誤');
},
success: function(response) {
$("#ID").html($.trim(response));
}
});
var organ
$.ajax({
url: '/html/text/pages/Mean.jsp',
dataType: 'html',
type:'POST',
async:false,
data: { No: div, Size: organ },
error: function(xhr) {
alert('Ajax request 發生錯誤');
},
success: function(response) {
$("#ID").html($.trim(response));
}
});
2015年3月19日 星期四
Jsp : 轉成csv (download csv)
<%@ page language="java" contentType="text/html; charset=BIG5" %>
<%@ page import="java.util.*" %>
<%
ArrayList list = new ArrayList();
list = from select database data (use map in list)
String filename = "test.csv";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
out.clear();
out.write("COM1NAME,COM2NAME");
out.newLine();
if(list.size()>0 )
{
for(int i=0; i<list.size(); i++)
{
HashMap map = (HashMap)list.get(i);
out.write(map.get("COM1")+","+map.get("COM2") );
out.newLine();
}
}
%>
<%@ page import="java.util.*" %>
<%
ArrayList list = new ArrayList();
list = from select database data (use map in list)
String filename = "test.csv";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
out.clear();
out.write("COM1NAME,COM2NAME");
out.newLine();
if(list.size()>0 )
{
for(int i=0; i<list.size(); i++)
{
HashMap map = (HashMap)list.get(i);
out.write(map.get("COM1")+","+map.get("COM2") );
out.newLine();
}
}
%>
訂閱:
文章 (Atom)