从JavaScript数组同时填充多个输入
我正在尝试用目标名称选择框中选择的选项值填充右提升和赤纬框,但是还没有成功,我该怎么做 脚本完成了我想要的一切,包括填充下一个下拉列表,然后填充底部的表格,但是我无法填充右上升和下降框 我已经在这里搜索了教程和其他回答的问题,但还没有找到任何有用的东西 常数天球=[{ id:134578521, 姓名:M15,, 赤经:21:29:58.33, 赤纬:+12:10:01.2, 过滤器:[{ 姓名:红R,, 值:['M15',21:29:58.33,+12:10:01.2,'N/A','Red R','p id=datetime>',] }, { 姓名:格林V, 值:['M15',21:29:58.33,+12:10:01.2,'N/A','Green V','p id=datetime>',] }, { 姓名:蓝B, 值:['M15',21:29:58.33,+12:10:01.2,'N/A','Blue B','p id=datetime>',] } ] }, { id:21412155, 姓名:M27, 阿森松岛:19:59:36.34, 赤纬:+22:43:16.09, 过滤器:[{ 姓名:红R,, 值:['M27',19:59:36.34,+22:43:16.09,'N/A','Red R','p id=datetime>',] }, { 姓名:格林V, 值:['M27',19:59:36.34,+22:43:16.09,'N/A','Green V','p id=datetime>',] }, { 姓名:蓝B, 值:['M27',19:59:36.34,+22:43:16.09,'N/A','Blue B','p id=datetime>',] } ] }, { 识别号:452456321347564364, 名称:NGC891, 阿森松岛:02:22:33.4, ra:02:22:33.4, 赤纬:+42:20:57.0, 十二月:+42:20:57.0, 过滤器:[{ 姓名:红R,, 值:['NGC891',02:22:33.4,+42:20:57.0,'N/A','Red R','p id=datetime>',] }, { 姓名:格林V, 值:['NGC891',02:22:33.4,+42:20:57.0,'N/A','Green V','p id=datetime>',] }, { 姓名:蓝B, 值:['NGC891',02:22:33.4,+42:20:57.0,'N/A','Blue B','p id=datetime>',] } ] } ]; const sphere_options=spheres=>spheres.mapsphere=>`${sphere.name}`.join; const filter_options=filters=>filters.mapfilter=>`${filter.name}`.join; 常量球体过滤器行=id,过滤器=>{ const cells=filter.values.mapvalue=>`${value}`.join; 返回`${cells}`; }; const select_sphere=event=>{ const sphere_id=parseintent.target.value,10; const sphere=天体球。findsphere=>sphere.id==sphere\u id; if!sphere抛出新错误'application.select_sphere-找不到id为${sphere_id}的球体; 否则{ const filter_selection=document.querySelector'sphere_filters'; const filters=filter_optionsphere.filters; filter_selection.innerHTML=`请选择一个筛选器…${filters}`; const header=document.querySelector'sphere_name'; header.innerHTML=sphere.name; const ascension=document.querySelector'right_ascension'; ascension.innerText=sphere.ascention; const declination=document.querySelector'declination'; declination.innerText=sphere.declination; const sphere_rows=document.querySelector'sphere_rows'; sphere_rows.innerHTML=; } }; 常量选择过滤器=事件=>{ const sphere_id=parseIntdocument.querySelector'Sessional_spheres'。值为10; const sphere=天体球。findsphere=>sphere.id==sphere\u id; const filter_name=event.target.value; const filter=sphere.filters.findfilter=>filter.name===filter\u name; 常量行=球体\过滤器\行球体\ id,过滤器; const sphere_rows=document.querySelector'sphere_rows'; sphere_rows.innerHTML=行; }; const show_detail=事件=>{ const row=event.target.closest'tr'; const sphere_id=parseIntrow.getAttribute'id'。切片7,10; const sphere=天体球。findsphere=>sphere.id==sphere\u id; 警报`您单击了sphere${sphere_id}的值${event.target.innerText}。`; //使用单击的单元格执行操作 }; window.addEventListener'DOMContentLoaded',=>{ const sphere_selection=document.querySelector“天球”; sphere_selection.innerHTML+=球体选项天体; sphere\u selection.addEventListener'change',选择\u sphere; const filter_selection=document.querySelector'sphere_filters'; 筛选选择。添加EventListener“单击”,选择筛选; const sphere_rows=document.querySelector'sphere_rows'; sphere_rows.addEventListener“单击”,显示详细信息; }; $document.readyfunction{ $'[data toggle=tooltip]'。工具提示; }; 目标名称: 选择一个目标。。。 权利提升: 赤纬: 滤器 选择一个过滤器。。。 曝光时间: 去 会话映像 目标名称 赤经 赤纬 曝光时间秒 滤器 时间戳UTC 图像类型从JavaScript数组同时填充多个输入,javascript,html,Javascript,Html,我正在尝试用目标名称选择框中选择的选项值填充右提升和赤纬框,但是还没有成功,我该怎么做 脚本完成了我想要的一切,包括填充下一个下拉列表,然后填充底部的表格,但是我无法填充右上升和下降框 我已经在这里搜索了教程和其他回答的问题,但还没有找到任何有用的东西 常数天球=[{ id:134578521, 姓名:M15,, 赤经:21:29:58.33, 赤纬:+12:10:01.2, 过滤器:[{ 姓名:红R,, 值:['M15',21:29:58.33,+12:10:01.2,'N/A','Red
您的脚本永远不会到达应该填充上升和下降框的位置,因为select_sphere函数已在此处崩溃:
const header = document.querySelector( '#sphere_name' );
您没有与此id匹配的HTML元素
好吧,假设有,它将使下一行崩溃:
const ascension = document.querySelector( '#right_ascension' );
匹配输入字段的ID为right\u Asception而非right\u Asception
即使修复了这两个bug,它也会再次崩溃:
ascension.innerText = sphere.ascention;
对象球体没有关键点上升。没错
此外,我建议为输入框指定一个唯一的名称,并使用document.getElementById而不是querySelector获取对它的引用。所以在正确提升的情况下
<input id="right_ascention_input" type="text" placeholder="HH:MM:SS.S" name="ascension" class="form-control" aria-required="true" aria-invalid="false">
并使用.value属性而不是.innerText来计算它
请看这里:
常数天球=[{
id:134578521,
姓名:M15,,
赤经:21:29:58.33,
赤纬:+12:10:01.2,
过滤器:[{
姓名:红R,,
值:['M15',21:29:58.33,+12:10:01.2,'N/A','Red R','p id=datetime>',]
},
{
姓名:格林V,
值:['M15',21:29:58.33,+12:10:01.2,'N/A','Green V','p id=datetime>',]
},
{
姓名:蓝B,
值:['M15',21:29:58.33,+12:10:01.2,'N/A','Blue B','p id=datetime>',]
}
]
},
{
id:21412155,
姓名:M27,
阿森松岛:19:59:36.34,
赤纬:+22:43:16.09,
过滤器:[{
姓名:红R,,
值:['M27',19:59:36.34,+22:43:16.09,'N/A','Red R','p id=datetime>',]
},
{
姓名:格林V,
值:['M27',19:59:36.34,+22:43:16.09,'N/A','Green V','p id=datetime>',]
},
{
姓名:蓝B,
值:['M27',19:59:36.34,+22:43:16.09,'N/A','Blue B','p id=datetime>',]
}
]
},
{
识别号:452456321347564364,
名称:NGC891,
阿森松岛:02:22:33.4,
ra:02:22:33.4,
赤纬:+42:20:57.0,
十二月:+42:20:57.0,
过滤器:[{
姓名:红R,,
值:['NGC891',02:22:33.4,+42:20:57.0,'N/A','Red R','p id=datetime>',]
},
{
姓名:格林V,
值:['NGC891',02:22:33.4,+42:20:57.0,'N/A','Green V','p id=datetime>',]
},
{
姓名:蓝B,
值:['NGC891',02:22:33.4,+42:20:57.0,'N/A','Blue B','p id=datetime>',]
}
]
}
];
const sphere_options=spheres=>spheres.mapsphere=>`${sphere.name}`.join;
const filter_options=filters=>filters.mapfilter=>`${filter.name}`.join;
常量球体过滤器行=id,过滤器=>{
const cells=filter.values.mapvalue=>`${value}`.join;
返回`${cells}`;
};
const select_sphere=event=>{
const sphere_id=parseintent.target.value,10;
const sphere=天体球。findsphere=>sphere.id==sphere\u id;
if!sphere抛出新错误'application.select_sphere-找不到id为${sphere_id}的球体;
否则{
const filter_selection=document.querySelector'sphere_filters';
const filters=filter_optionsphere.filters;
filter_selection.innerHTML=`请选择一个筛选器…${filters}`;
//const header=document.querySelector'sphere_name';
//header.innerHTML=sphere.name;
const ascension=document.getElementById‘右上升输入’;
ascension.value=sphere.right\u ascension;
const declination=document.getElementById'declination_input';
declination.value=球体declination;
const sphere_rows=document.querySelector'sphere_rows';
sphere_rows.innerHTML=;
}
};
常量选择过滤器=事件=>{
const sphere_id=parseIntdocument.querySelector'Sessional_spheres'。值为10;
const sphere=天体球。findsphere=>sphere.id==sphere\u id;
const filter_name=event.target.value;
const filter=sphere.filters.findfilter=>filter.name===filter\u name;
常量行=球体\过滤器\行球体\ id,过滤器;
const sphere_rows=document.querySelector'sphere_rows';
sphere_rows.innerHTML=行;
};
const show_detail=事件=>{
const row=event.target.closest'tr';
const sphere_id=parseIntrow.getAttribute'id'。切片7,10;
const sphere=天体球。findsphere=>sphere.id==sphere\u id;
警报`您单击了sphere${sphere_id}的值${event.target.innerText}。`;
//使用单击的单元格执行操作
};
const sphere_selection=document.querySelector“天球”;
sphere_selection.innerHTML+=球体选项天体;
sphere_selection.addEventList
ener'change',选择_球体;
const filter_selection=document.querySelector'sphere_filters';
筛选选择。添加EventListener“单击”,选择筛选;
const sphere_rows=document.querySelector'sphere_rows';
sphere_rows.addEventListener“单击”,显示详细信息;
目标名称:
选择一个目标。。。
权利提升:
赤纬:
滤器
选择一个过滤器。。。
曝光时间:
去
会话映像
目标名称
赤经
赤纬
曝光时间秒
滤器
时间戳UTC
图像类型
您的代码段未运行。请添加相关的jQUery和工具提示脚本标记您缺少元素sphere\u name和right\u ascension,并且您的按钮正在执行保留功能。还要加上jQuery和jQuery-UIT谢谢你的帮助,我为没有早点感谢你而道歉,那天晚上我在回家的路上被人从自行车上撞倒了,从那时起我就有点害怕了。我想知道您是否可以就如何通过点击Go来填充表提供建议!按钮,而不是单击第二个选择框中的选项