大家好,每当用户使用 jquery 单击文本框时,我都会尝试获取文本框的值,但是当我使用alert() 查看这些值时,这就是我得到的值:
function (value) {
var hooks, ret, elem = this[0];
if (!arguments.length) {
if (elem) {
hooks = jQuery.valHooks[elem.nodeName.toLowerCase()] ||
jQuery.valHooks[elem.type];
if (hooks &&
"get" in hooks &&
(ret = hooks.get(elem, "value")) !== undefined) {
return ret;
}
ret = elem.value;
return typeof ret === "string" ? ret.replace(rreturn, "") : ret == null ? "" : ret;
}
return undefined;
}
var isFunction = jQuery.isFunction(value);
return this.each(function (i) {var self = jQuery(this), val;if (this.nodeType !== 1) {return;}if (isFunction) {val = value.call(this, i, self.val());} else {val = value;}if (val == null) {val = "";} else if (typeof val === "number") {val += "";} else if (jQuery.isArray(val)) {val = jQuery.map(val, function (value) {return value == null ? "" : value + "";});}hooks = jQuery.valHooks[this.nodeName.toLowerCase()] || jQuery.valHooks[this.type];if (!hooks || !("set" in hooks) || hooks.set(this, val, "value") === undefined) {this.value = val;}});}
这是我的代码:http://jsfiddle.net/QYHXu/1/
请帮忙。预先非常感谢。
最佳答案
$(this).val
...是一个函数。
$(this).val()
...是该函数的返回值。使用$(this).val()
。
关于jquery - 如何从文本框中获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8258551/