现在的位置: 首页 > 综合 > 正文

JS表单大全

2012年06月01日 ⁄ 综合 ⁄ 共 436字 ⁄ 字号 评论关闭

【创建表单并提交】

function submitXML(xml) {
	var f = document.createElement("form");
	f.method = "post";
	f.action = "xmlServlet";
	document.body.appendChild(f);
	var i = document.createElement("input");
	i.type = "hidden";
	i.name = "xml";
	i.value = xml;
	f.appendChild(i);
	f.submit();
}

【只允许输入整数】

function check(txt) {
	if (event.keyCode != 13) return;
	if (String(parseInt(txt.value)).length != txt.value.length) {
		alert(txt.alt);
	}
}
……
<input type="text" name="num" alt="必须输入整数" onkeyup="check(this)"/>

抱歉!评论已关闭.