js获取页面html


页面中有动态添加的数据,直接用html获取不到input等标签动态添加的值

function getHTML() {
        $('#dv :input').each(function () {
            ///////////获取容器innerHTML要想包含输入的值,需要设置过value属性。其他对象重置selected、checked属性
            switch (this.type) {
                case 'text': this.setAttribute('value', this.value); break;
                case 'checkbox':
                case 'radio':
                    if(this.checked)this.setAttribute('checked', 'checked');
                    else this.removeAttribute('checked');
                    break;
                case 'select-one':
                case 'select-multiple':
                    $(this).find('option').each(function () {
                        if(this.selected)this.setAttribute('selected', 'selected');
                        else this.removeAttribute('selected');
                    });
                    break;
                case 'textarea': this.innerHTML = this.value; break;
            }
        });
        alert($('#dv').html())
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM