我如何从数组中获取信息并将其发送到输入? 我有一个过滤器,在过滤信息后我有2个值(v1,v2)和2个按钮 - 用于v1和v2。我需要按下来自mynewvarv1的按钮v1信息输入whith id =' one' - 你能帮我写这个功能吗? 对不起我的英文
var myvar = [ // filter start
{name:'v1',val1:'31',val2:'',val3:true,val4:false,val5:false,val6:false,},
{name:"Срочный на 91 день",val1:'91',val2:'',val3:true,val4:false,val5:false,val6:false,},
{name:"v2",val1:'181',val2:'',val3:true,val4:false,val5:false,val6:false,},
];
document.getElementById('filterButton').onclick = function(){
var filter = [];
filter.push(document.getElementById('val1').options[document.getElementById('val1').selectedIndex].value);
filter.push(document.getElementById('val2').value);
filter.push(rbvalue('val3')=='1');
filter.push(rbvalue('val4')=='1');
filter.push(rbvalue('val5')=='1');
var filtered_data = [];
var data_accepted = true;
for(i=0;i<myvar.length;i++){
data_accepted = true;
for(j=0;j<filter.length;j++){
if(filter[j]!=='' && filter[j]!=myvar[i][('val'+(j+1))]){
data_accepted = false;
}
}
if(data_accepted){
filtered_data.push(myvar[i]);
}
}
function getmesseg (){
container.innerHTML = ' v1 <button onclick="myFunction()">Try it</button>'
container.innerHTML = ' v2<button onclick="myFunction()">Try it</button>'
var mynewvarv1 = [ {vaal1:value="12",vaal2:'10.2',vaal3:'9',} ];
var mynewvarv2 = [ {vaal1:value="12",vaal2:'10.2',vaal3:'9',} ];
//what the function this needs???
};
function ab(){ if(filtered_data[i].name == "v1","v2") {getmesseg(); }};
var container = document.getElementById('container');
container.innerHTML = '';
for(i=0;i<filtered_data.length;i++){
container.innerHTML+=filtered_data[i].name+'<br />';
ab();
}
};
function rbvalue(html_name){
var undefined,default_value,i,rb_collection = document.getElementsByName(html_name);
if(rb_collection!==undefined){
default_value = rb_collection[0].value;
}
for(i=0;i<rb_collection.length;i++){
if(rb_collection[i].checked){
return rb_collection[i].value;
}
}
return default_value;
}// filter end
答案 0 :(得分:0)
你应该可以使用:
var input1 = document.getElementById("one");
input1.value = mynewvarv1[0].vaal1;