如何写一个onblur函数来杀死这个锚标签?

时间:2010-12-09 20:01:34

标签: javascript dojo onblur

我为508合规编写了这段代码但是在用户选中它之后我希望元素能够如何实现这一目标?这是以下内容:

handleInteraction:function(focusable){
    this.setElements();
    var totalAllowed = (this.elements.totalChar[0].innerHTML);
    var value = this.obj.value;
    var chars = value.length;
    var charsLeft = parseInt(totalAllowed) - parseInt(chars);
    if (charsLeft >= 0 || (typeof focusable=='boolean' && focusable==false)){
        this.elements.leftChar[0].innerHTML = charsLeft;
        this.elements.charLeftp.removeClass("error");           
    }
    else {
        this.obj.value = value.substring(0, totalAllowed);
        this.elements.leftChar[0].innerHTML = 0;
        this.elements.charLeftp.addClass("error")
        var divNA = dojo.byId("max-"+this.obj.id);
        if (divNA){
            dojo.destroy(divNA);    
        }
        divNA = dojo.create("a",{"id":"max-"+this.obj.id,"class":"hide-fromsighted","innerHTML":"<h5>This textarea has reached the maximum allowed number of characters. Please navigate backwards!</h5>","tabindex":"-1"});
        dojo.place(divNA,this.obj,'after');
        divNA.focus();


        /*
         * Here apply the onblur event to kill the <a>
         */
    }

2 个答案:

答案 0 :(得分:2)

我假设您正在使用Dojo Toolkit。您可以使用dojo.destroy销毁<a>标记,并且可以使用dojo.stopEvent来停止<a>事件传播。

http://www.dojotoolkit.org/reference-guide/dojo/destroy.html#dojo-destroy

http://www.dojotoolkit.org/reference-guide/dojo/stopEvent.html#dojo-stopevent

答案 1 :(得分:1)

怎么样:

divNA.onblur = function() { divNA.destroy(); }

那会有用吗?