全部代码如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>在JavaScript中重写对象的方法</title>
<script src="Scripts/jquery-1.8.2.min.js"></script>
<script src="Scripts/jquery-ui-1.8.24.min.js"></script>
<script>
$.prototype.val = function (base) {
return function () {
var s = this, a = "data-property", p = s.attr(a), isset = arguments.length > 0, v = isset ? arguments[0] : null;
if (isset&&typeof(base)=="function") { base.call(s, v); } else { v = base.call(s); }
if (p) {
if (isset) { s.attr(p, v); return s }
else { return s.attr(p) }
}
else {
if (!s.is(":input"))
{ if (isset) { s.text(v); return s; } else { return s.text(); } }
else { return isset ? s : v; }
}
}
}($.prototype.val);
</script>
</head>
<body>
<span id="lbl">Hello world!</span>
<input type="text" id="txt" value="hello world" />
<input type="checkbox" value="哈哈哈。。。" />
</body>
</html>希望本文所述对大家的web前段设计有所帮助。










