input:text 的value 和 attribute('value') 不是一回事

如题,input:text 当手工输入字符改变其值时,两者就不一样了。

要获得手工输入,不要用attribute('value'), 直接使用value

    function getbyid(id){
        return document.getElementById(id);
    }

    window.onload = function(){
        content = getbyid('content');
        change = getbyid('change');

        change.addEventListener('click', function(){
            content.setAttribute('value',
                parseInt(content.getAttribute('value'))+1);

            console.log( 
                       '原生val:'+ content.value + " " +  
                       '原生attr:'+ content.getAttribute('value')+ "   " + 
                         
                       'jquery val:'+$('#content').val() + "   " + 
                       'jquery attr:'+$('#content').attr('value') + "   "   
                );

        }, false);
    };

 

posted @ 2015-06-07 18:22  忘忧般若汤  阅读(295)  评论(0编辑  收藏  举报