我想将从 textarea 获得的字符串值传递给 focus() 和 blur(),但为什么我会得到 [object object]?
我使用 each() 成功获取了每个 textarea 的字符串值,并将字符串存储在 var 中 -var value_default = $this.val();
然后我将其传递var
给$this.focus(function (value_default) {..})
-我是否错误地传递了它?
如果我提醒这一点value_default
,我将得到 [object oject] - alert(value_default);
下面是完整的代码,如果您需要查看它...
$(".autohide").each(function(){
/* set the variable and store its value */
var $this = $(this);
var value_default = $this.val();
var parent_autohide = $this.parents('form');
var parent_button = $('input[type=submit]',parent_autohide).parents("div:.item-form").hide();
var parent_marginbottom = parseInt($this.parents("div:.item-form").css("marginBottom"));
$this.parents("div:.item-form").css({margin:'0px'});
alert(value_default); // I will get the string value of each textarea element
$this.focus(function (value_default) {
alert(value_default); // I will get [object object]
var $this = $(this);
$this.elastic();
$this.parents('div:.item-form').css({margin:'0px 0px '+parent_marginbottom+'px 0px'});
var $this_parent = $this.parents('form');
var $this_button = $('input[type=submit]',$this_parent).parents("div:.item-form").show();
}).blur(function(value_default){
alert(value_default); // I will get [object object]
var $this = $(this);
var value_current = $this.val();
if ( value_current == value_default)
{
$this.css({ height: 'inherit'});
$this.parents('div:.item-form').css({margin:'0px'});
var $this_parent = $this.parents('form');
var $this_button = $('input[type=submit]',$this_parent).parents("div:.item-form").hide();
}
});
});
非常感谢。
编辑:
我知道是什么导致了 IE 上的错误 -
$this.css({height: 'inherit'}); // this line will create error on IE
$this.css({height:''}); // IE likes this
那么“继承”IE不会像其他浏览器那样接受它有什么问题!??