`
gkm422
  • 浏览: 81678 次
  • 性别: Icon_minigender_1
  • 来自: 太原
社区版块
存档分类
最新评论

JQuery表单用例(一)

阅读更多

      有时侯告诉用户应该怎么做很重要,尤其是当填写一个复杂的表格的时候.此代码使用title属性在一个单独的DOM元素里显示帮助。(翻译的生硬了...)

     

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title></title>
		<script type="text/javascript" src="jquery.js"></script>
		<script type='text/javascript' src='jquery.autohelp.js'></script>	</head>

	<body>
<form>
	<input type="text" name="demo1" title="Type something" />
	<select name="demo2" title="Select something"><option value=0>Select</option></select>
	<input type="radio" name="demo3" value="foo" title="Pick one (like foo)"> foo
	<input type="radio" name="demo3" value="bar" title="Pick one (like bar)"> bar
</form>
<p id="autohelp">Focus on one of the form elements above.</p>
<script type="text/javascript">
$(document).ready(function() {
	$("form *").autohelp("#autohelp");
});
</script>
</body>
</html>

 

jquery.js这个从那啥网上下就行...

jquery.autohelp.js 代码

$.fn.autohelp = function(t, o) {
	t = $(t); o = o || {};
	var h;
	this.focus(function() { h = t.html(); (o.hide ? t.show() : t).html(this.title); })
	    .blur(function() { (o.hide ? t.hide() : t).html(h); });
	return this;
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics