表单左侧自动调整,应用广泛,不用单独添加宽度
表单左侧自动调整,解决了单独添加宽度的烦恼,同事添加
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>表单左侧宽度自动调整</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">label{float:left; margin-right:2px; text-align:right; line-height:26px;}span{ margin-left:4px;}input{ border:1px solid #ccc; height:26px; line-height:26px; vertical-align:middle;}</style><script type="text/javascript" src="http://jt.875.cn/js/jquery"></script><script type="text/javascript"> $(function(){ var max=0; $("label").each(function(){ if ($(this).width() > max) max=$(this).width(); }); $("label").width(max); }) </script></head><body><p><label>姓名:</label><input type="text" ><span>请输入正确的名称</span></p><p><label>您的地址:</label><input type="text" ><span>请输入正确的地址</span></p><p><label>用户名:</label><input type="text" ></p><p><label>姓名:</label><input type="text" ></p></body></html>