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

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

如何將 JavaScript 變量設(shè)置為文本區(qū)域標記的內(nèi)容?

如何將 JavaScript 變量設(shè)置為文本區(qū)域標記的內(nèi)容?

胡子哥哥 2024-01-03 16:47:37
我目前正在嘗試將 JavaScript 變量設(shè)置為輸入到第一個<textarea>標簽中的任何內(nèi)容,但它不起作用,而且我不知道如何修復它,因為我對 JavaScript 沒有太多經(jīng)驗。非常感謝任何人的幫助。我沒有嘗試過任何其他的事情,因為我想不出有什么可以嘗試的。var t =  document.getElementById("text").valuefunction func() {    document.getElementById("ascii").value = t;}.con {    display: flex;     margin-top: 2px;    margin-left: 20px;}.button {    background: #4CAF50;    border: none;    outline: none;    color: #ffffff;    padding: 14px;    height: 60px;    width: 140px;    border-radius: 0 10px;    margin-top: 0px;    font-size: 22px;    cursor: pointer;}.txt {    display: flex;     margin-right: 20px;    background: #ffffff;    border: 0;    outline: none;    height: 700px;    width: 45%;    border-radius: 10px;    box-shadow: 0 4px 8px 0 rgba(141, 105, 105, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);    margin-top: 0px;}.text {    border: none;    margin-top: 18px;    margin-left: 18px;    height: 660px;    width: 630px;    outline: none;    font-size: 22px;    resize: none;}.asci {    background: #ffffff;    border: 0;    outline: none;    height: 700px;    width: 45%;    border-radius: 10px;    box-shadow: 0 4px 8px 0 rgba(141, 105, 105, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);}.ascii {    border: none;    margin-top: 20px;    margin-left: 10px;    height: 660px;    width: 640px;    outline: none;    font-size: 22px;    resize: none;}<html><head>    <title>alphabetical order machine</title>    <link rel="stylesheet" href="ascii.css"></head><body>    <div class="con">        <!--button onclick="func()">button</button-->    <form class="txt">        <textarea class="text" id="text" type="text" placeholder="type your text here!"></textarea>                <input class="button" type='button' value="alphabetize" onclick="func()">    </form>    <form class="asci">        <textarea class="ascii" id="ascii" type="text"></textarea>    </form>    </div>    <script src="ascii.js"></script></body></html>
查看完整描述

3 回答

?
楊魅力

TA貢獻1811條經(jīng)驗 獲得超6個贊

var t =  document.getElementById("text").value

function func() {

    document.getElementById("ascii").value = t;

}

目前您的var t =  document.getElementById("text").value代碼只會執(zhí)行一次。第一次,該值將為“”,因為 textArea 第一次為空。


您需要將其移動到內(nèi)部,func()以便每次func()執(zhí)行時都會獲得最新值


function func() {

    var t =  document.getElementById("text").value

    document.getElementById("ascii").value = t;

}


查看完整回答
反對 回復 2024-01-03
?
ABOUTYOU

TA貢獻1812條經(jīng)驗 獲得超5個贊

將 var 聲明放入函數(shù)中:


function func() {

   var t =  document.getElementById("text").value

   document.getElementById("ascii").value = t;

}


查看完整回答
反對 回復 2024-01-03
?
largeQ

TA貢獻2039條經(jīng)驗 獲得超8個贊

您僅聲明一次值,t而無法在單擊按鈕時查找并獲取該值。任何您想要多次執(zhí)行的任務(wù)都必須在函數(shù)或重復出現(xiàn)的表達式中,等等。以下演示僅在函數(shù)外部聲明一個變量,其余變量在函數(shù)內(nèi)部 - 詳細信息在演示中注釋。


順便說一句,如果您正在處理表單字段(例如輸入、輸出、文本區(qū)域等),那么您有必要扭曲表單中的所有內(nèi)容并使用表單來管理所有表單字段。


演示

// Reference the form

const editor = document.forms.editor;


// Register the form to the input event

editor.oninput = edit;


// pass the event object

function edit(event) {


  /*

  = 'this' is the form

  = `field` is a NodeList of inputs, buttons, textareas, 

     etc

  */

  const field = this.elements;

  

  /*

  = event.target is the tag the user interacted with 

    In this case it would be textarea#in

  */

  const input = event.target;

  

  // Reference textarea#out

  const output = field.out;

  

  /*

  = if the event.target is textarea#in...

  = Set the value of textarea#out to the value of

    textarea#in 

  */

  if (input.id === 'in') {

    output.value = input.value;

  }

}

<form id='editor'>

  <textarea id='in'></textarea>

  <textarea id='out'></textarea>

</form>


查看完整回答
反對 回復 2024-01-03
  • 3 回答
  • 0 關(guān)注
  • 191 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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