第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

Firefox中的jQuery html()(使用.innerHTML)忽略DOM更改

Firefox中的jQuery html()(使用.innerHTML)忽略DOM更改

吃雞游戲 2019-10-21 10:41:27
我真的很驚訝,我之前從未遇到過此問題,但是似乎在元素上調(diào)用jQueries .html()函數(shù)會忽略DOM中的更改,即它會返回原始源中的HTML。IE不會這樣做。jQueries .html()僅在內(nèi)部使用innerHTML屬性。這是要發(fā)生嗎?我使用的是Firefox 3.5.2。我在下面有一個(gè)示例,無論您將文本框的值更改為什么,“ container”元素的innerHTML都只會返回HTML標(biāo)記中定義的值。該示例并沒有使用jQuery只是為了使其更簡單(使用jQuery的結(jié)果是相同的)。有誰能解決我可以在哪個(gè)位置獲取容器html的當(dāng)前狀態(tài),即包括對DOM的任何腳本化更改?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >    <head>        <script type="text/javascript">            <!--            function BodyLoad(){                                document.getElementById("textbox").value = "initial UPDATE";                DisplayTextBoxValue();            }            function DisplayTextBoxValue(){                alert(document.getElementById("container").innerHTML);                             return false;            }            //-->        </script>    </head>    <body onload="BodyLoad();">        <div id="container">            <input type="text" id="textbox" value="initial" />        </div>        <input type="button" id="button" value="Test me" onclick="return DisplayTextBoxValue();" />    </body></html>
查看完整描述

3 回答

?
小唯快跑啊

TA貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊

Firefox沒有更新的value 屬性基于用戶輸入DOM對象的,只是它的value 性能 -相當(dāng)快,工作的周邊存在。


DOM:


function DisplayTextBoxValue(){

  var element = document.getElementById('textbox');

  // set the attribute on the DOM Element by hand - will update the innerHTML

  element.setAttribute('value', element.value);

  alert(document.getElementById("container").innerHTML);             

  return false;

}

.formhtml()自動執(zhí)行此操作的jQuery插件:


(function($) {

  var oldHTML = $.fn.html;


  $.fn.formhtml = function() {

    if (arguments.length) return oldHTML.apply(this,arguments);

    $("input,button", this).each(function() {

      this.setAttribute('value',this.value);

    });

    $("textarea", this).each(function() {

      // updated - thanks Raja & Dr. Fred!

      $(this).text(this.value);

    });

    $("input:radio,input:checkbox", this).each(function() {

      // im not really even sure you need to do this for "checked"

      // but what the heck, better safe than sorry

      if (this.checked) this.setAttribute('checked', 'checked');

      else this.removeAttribute('checked');

    });

    $("option", this).each(function() {

      // also not sure, but, better safe...

      if (this.selected) this.setAttribute('selected', 'selected');

      else this.removeAttribute('selected');

    });

    return oldHTML.apply(this);

  };


  //optional to override real .html() if you want

  // $.fn.html = $.fn.formhtml;

})(jQuery);


查看完整回答
反對 回復(fù) 2019-10-21
?
長風(fēng)秋雁

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個(gè)贊

感謝您的formhtml插件。為了配合使用textarea,我必須對其進(jìn)行更新:


$("textarea", this).each(function() { 

  $(this).text($(this).val()); 

});


查看完整回答
反對 回復(fù) 2019-10-21
  • 3 回答
  • 0 關(guān)注
  • 557 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號