houxiaobei

页面中有动态添加的数据,直接用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())
    }

分类:

技术点:

相关文章:

  • 2021-10-19
  • 2021-12-03
  • 2021-11-30
  • 2021-11-27
  • 2021-12-26
  • 2021-12-08
  • 2022-12-23
猜你喜欢
  • 2021-12-04
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案