Javascript,通过2个事件更新值并连接
一个简单的问题。 我有两个控件更改事件 我有第一件事:Javascript,通过2个事件更新值并连接,javascript,events,concatenation,Javascript,Events,Concatenation,一个简单的问题。 我有两个控件更改事件 我有第一件事: 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 = '
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);
});
当我选择“向下”时,我的text1.textfield中有“D”
在显示在Test2.textbox中的第二个事件中:
ctrlEspesor.on ('keyup', function(e){
if (this.getValue()!== ''){
var strEspesor = ctrlEspesor.getValue();}
ctrlTest2.setValue(strEspesor);
当我输入'4'时,我有'4'
这两项活动都有效。
但现在我尝试将strProducto
和stresperor
连接到ctrlTest3.textbox
(之前在ctrlTest1
和ctrlTest2
中没有显示)
但每次用户更改这两个值中的一个时,我都需要动态更新
我试着这样做,但没有成功
var valueFinal = strProducto.concat(strEspesor);
ctrlTest3.setValue(valueFinal);
ctrlTest3
示例:“D4”
欢迎您的大力帮助,谢谢….我试着理解您的意思。
检查一下这个
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">
向上的
向下
左边
赖特
对于valueFinal,您不能在函数中调用strProducto和stresperor,因为范围问题,解决方案是全局设置有问题的两个变量
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);
阿德尔B的秘诀很管用。但在普伦纳的领导下,我认为情况有所不同。我尝试使用以下内容改编Abel D代码:
var select = Runner.getControl(pageid,'Producto_tipo');
var txt1 = Runner.getControl(pageid,'Producto_tipo');
var txt2 = Runner.getControl(pageid,'Espesor');
var txt3 = Runner.getControl(pageid,'EspesorNEW');
//select.addEventListener('change', (e)=>{ //<- with '=>' I have error
select.addEventListener('change', function(e){
//txt1.value = e.target.value;
txt1.value = e.target.value;
//txt3.value = txt1.value + txt2.value;
txt3.value = txt1.value + txt2.value;
})
//txt2.addEventListener('keyup', (e)=>{//<- with '=>' I have error
txt2.addEventListener('keyup', function(e){
//txt3.value = txt1.value + (txt2.value);
txt3.value = txt1.value + (txt2.value);
})
var select=Runner.getControl(pageid,'Producto_tipo');
var txt1=Runner.getControl(pageid,'Producto_tipo');
var txt2=Runner.getControl(pageid,'Espesor');
var txt3=Runner.getControl(pageid,'EspesorNEW');
//select.addEventListener('change',(e)=>{/{//这对您的示例很好。这正是我想要的。但是在我的示例中,我对select.addEventListener('change',(e)=>{
我使用phprunner,它是不同的。最后两行不起作用。我什么都没有。最后两行可能需要一个事件?我只报告设置的代码,但肯定需要一个事件。