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