代码之家  ›  专栏  ›  技术社区  ›  user2828442

将html代码传递给php时出现的对象HTMLDivElement-Angular

  •  0
  • user2828442  · 技术社区  · 6 年前

    我们在变量中有html代码。我们想用 php 并保存在mysql中。

    home.ts 侧码:

    this.divCodesub = document.getElementById(this.selectedDivCodesub);
    console.log (this.divCodesub);
    

    数据输入控制台.log是:

    <div id="0"><div id="change_color" class="heading-back context_menu"><div class="row"><div contenteditable="true" class="col-md-12 heading-sec context_menu">Hi there, Im <span contenteditable="true" class="head-clr">STACK</span></div><div contenteditable="true" class="col-md-12 heading-sec context_menu">Smart, simple and responsive.</div></div></div></div>
    

    divCode:[对象HTMLDivElement] ,此消息出现在网络中。

    我们怎么才能通过呢?

    编辑:1 如何将变量发送到php,请参见下面的代码-

    代码:

        'divI='+this.list[this.selectedDivCodesub].div_id+'&divCode='+this.divCodesub;
                this._updateSection.callService(api,params).subscribe(data=>{
     ...
    });
    

    service.ts 代码:

     callService(api,params){
            var headers = new Headers();
            headers.append('Content-Type', 'application/x-www-form-urlencoded');
            return this._http.post(this._url+api,params+"&"+this.randomno,{headers:headers})
                   .map((response:Response) => response.json());
        }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   user4676340 user4676340    6 年前

    使用 outerHTML 属性将其转换为字符串。

    (打开控制台,看看它确实是一个字符串)

    const div = document.querySelector('div');
    console.log(typeof div);
    console.log(div.toString());
    console.log(typeof div.outerHTML);
    console.log(div.outerHTML);
    <div class="container">
      LOOK AT ME I'M A DIV
    </div>