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

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

Javascript,通過 2 個事件更新值并連接

Javascript,通過 2 個事件更新值并連接

慕的地6264312 2021-10-21 10:23:25
一個簡單的問題。我有 2 個控制更改事件。我有第一個事件:ctrlProducto_tipo.on  ('change', function(e){  if (this.getValue()== 'Up'){    var strProducto = 'U';}  if (this.getValue()== 'Down'){    var strProducto = 'D';}  if (this.getValue()== 'Left'){    var strProducto = 'L';}  if (this.getValue()== 'Right'){    var strProducto = 'R';}  ctrlTest1.setValue(strProducto);});當(dāng)我選擇“向下”時,我的text1.textfield“D”中有在我要顯示的第二個事件中Test2.textbox:ctrlEspesor.on  ('keyup', function(e){if (this.getValue()!== ''){var strEspesor = ctrlEspesor.getValue();}ctrlTest2.setValue(strEspesor);當(dāng)我輸入'4'時,我有'4'。這兩個事件有效。但是現(xiàn)在我嘗試連接strProducto和strEspesor到ctrlTest3.textbox(在ctrlTest1&之前不顯示ctrlTest2)。但是每次用戶更改兩個值之一時,我都需要ctrlText3即時更新。我試試這個,沒有成功。var valueFinal = strProducto.concat(strEspesor);ctrlTest3.setValue(valueFinal);示例ctrlTest3:'D4'歡迎提供大幫助,謝謝.....
查看完整描述

2 回答

?
函數(shù)式編程

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

使用 valueFinal,您不能在函數(shù)內(nèi)調(diào)用 strProducto 和 strEspesor 來解決作用域問題,解決方案是全局設(shè)置有問題的兩個變量。


var strProducto;  //globasl

ctrlProducto_tipo.on  ('change', function(e){

    if (this.getValue()== 'Up'){

        strProducto = 'U';}

    if (this.getValue()== 'Down'){

        strProducto = 'D';}

    if (this.getValue()== 'Left'){

        strProducto = 'L';}

    if (this.getValue()== 'Right'){

        strProducto = 'R';}

ctrlTest1.setValue(strProducto);

});


var strEspesor; //global

ctrlEspesor.on  ('keyup', function(e){

    if (this.getValue()!== ''){

        strEspesor = ctrlEspesor.getValue();}

ctrlTest2.setValue(strEspesor);



var valueFinal = strProducto.concat(strEspesor);

ctrlTest3.setValue(valueFinal);


查看完整回答
反對 回復(fù) 2021-10-21
?
慕碼人8056858

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

我試圖理解你的意思。在codepen 上檢查一下。


Javascript


var select = document.getElementById('select');

var txt1 = document.getElementById('text1');

var txt2 = document.getElementById('text2');

var txt3 = document.getElementById('text3');


select.addEventListener('change', (e)=>{

  txt1.value = e.target.value;

  txt3.value = txt1.value + txt2.value;

})


txt2.addEventListener('keyup', (e)=>{

  txt3.value = txt1.value + txt2.value;

})

HTML部分


  <select id="select">

    <option value="u">Up</option>

    <option value="d">Down</option>

    <option value="l">Left</option>

    <option value="r">Right</option>

  </select><br>

  <input type="text" id="text1"><br>

  <input type="text" id="text2"><br>

  <input type="text" id="text3">


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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