2 回答

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);

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">
添加回答
舉報