我想通过()的字符串值这是我从textarea的进入焦点和模糊(), 但为什么我会得到的是[对象对象]

我获取每个textarea的字符串值成功地与每个()和I的字符串存储在一个变种 - var value_default = $this.val();

然后,我通过这个var$this.focus(function (value_default) {..}) - ?我会传递给它错误地

如果我提醒这个value_default我将得到[对象oject] - 警报(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浏览器不会采取像其他浏览器!??

有帮助吗?

解决方案

作为评论者说,该函数创建处理该聚焦并且模糊具有被定义为value_default第一参数(事件参数),其覆盖声明越往上之一。

所以,如果你只是做应该工作:

.focus(function(){ .blur(function(){

因此,你应该能够访问你,因为它仍然是范围之内,而不是被你的函数参数覆盖之前声明value_default。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top