使用JavaScript拆分HTML值
当前,该选项从html中获取值,当选择某个项目时,将显示该选项的相应值使用JavaScript拆分HTML值,javascript,html,Javascript,Html,当前,该选项从html中获取值,当选择某个项目时,将显示该选项的相应值 // JavaScript Document calc = function(prodNum) { var total = prices[0]; Vstarterkit = (document.getElementById("starterkit").value); T1 = (document.getElementById("doorswitch").value * prices[1
// JavaScript Document
calc = function(prodNum) {
var total = prices[0];
Vstarterkit = (document.getElementById("starterkit").value);
T1 = (document.getElementById("doorswitch").value * prices[1]);
T2 = (document.getElementById("passiveir").value * prices[2]);
T3 = (document.getElementById("vibration").value * prices[3]);
T4 = (document.getElementById("keyfob").value * prices[4]);
T5 = (document.getElementById("keypad").value * prices[5]);
T6 = (document.getElementById("communicator").value * prices[6]);
T7 = (document.getElementById("linebox").value * prices[7]);
total += (document.getElementById("doorswitch").value * prices[1]);
total += (document.getElementById("passiveir").value * prices[2]);
total += (document.getElementById("vibration").value * prices[3]);
total += (document.getElementById("keyfob").value * prices[4]);
total += (document.getElementById("keypad").value * prices[5]);
total += (document.getElementById("communicator").value * prices[6]);
total += (document.getElementById("linebox").value * prices[7]);
total += (document.getElementById("starterkit").value * 1);
document.getElementById("Total_Cost").innerHTML = ""+total+".00";
document.getElementById("Price_Vstarterkit").innerHTML = ""+Vstarterkit+".00";
document.getElementById("Price_C1").innerHTML = ""+prices[1]+".00";
document.getElementById("Price_C1").innerHTML = ""+prices[1]+".00";
document.getElementById("Price_C2").innerHTML = ""+prices[2]+".00";
document.getElementById("Price_C3").innerHTML = ""+prices[3]+".00";
document.getElementById("Price_C4").innerHTML = ""+prices[4]+".00";
document.getElementById("Price_C5").innerHTML = ""+prices[5]+".00";
document.getElementById("Price_C6").innerHTML = ""+prices[6]+".00";
document.getElementById("Price_C7").innerHTML = ""+prices[7]+".00";
document.getElementById("Price_T1").innerHTML = ""+T1+".00";
document.getElementById("Price_T2").innerHTML = ""+T2+".00";
document.getElementById("Price_T3").innerHTML = ""+T3+".00";
document.getElementById("Price_T4").innerHTML = ""+T4+".00";
document.getElementById("Price_T5").innerHTML = ""+T5+".00";
document.getElementById("Price_T6").innerHTML = ""+T6+".00";
document.getElementById("Price_T7").innerHTML = ""+T7+".00";
}
我可以将这些值回调到我的html文档中,因此我需要使用JavaScript和分隔符进行拆分|
然后,这些将被作为值的子值调用,但在查看了几种可能性之后,我不知道如何执行此操作。有人能告诉我正确的方向吗。很酷,我知道了,但是搜索术语时非常混乱,因为有很多复杂的东西,我需要简单的东西。因此,在我的java中添加了以下行:-
299
built in
4 x A
1 x B
1 x C
1 x12V Battery
谢谢大家的帮助。@polywhill先生没必要粗鲁无礼。每个人都有不同的经验。你是使用java还是javascript来分割字符串?因为你的代码是用javascript编写的,这就是我要说的。你可以在谷歌上搜索“javascript字符串拆分”和“javascript字符串修剪”(trim用于删除字符串中的空格),谢谢我搜索了这么多,但是我尝试拆分的代码似乎不起作用,所以我显然做错了什么。所以我把它分成6个部分,用|隔开,然后我需要分别回忆这6个位。酷,得到了,但搜索术语时非常混乱,因为有很多复杂的东西,我需要简单的东西。因此将这些行添加到我的java中,var split=(document.getElementById(“starterkit”).value)将我的html值拆分为拆分[0]等文档。getElementById(“Price_Vstarterkit”)。innerHTML=“”+拆分[0]+“.00”;//根据html id文档返回值;document.getElementById(“Vaule2_Vstarterkit”).innerHTML=split[2];等等,谢谢,这很有效。
299
built in
4 x A
1 x B
1 x C
1 x12V Battery
var split = (document.getElementById("starterkit").value).split('|'); // splits my html value staterkit into splits[0] etc at each |
document.getElementById("Price_Vstarterkit").innerHTML = ""+split[0]+".00"; // returns values according to the html id
document.getElementById("Value1_Vstarterkit").innerHTML = split[1];
document.getElementById("Vaule2_Vstarterkit").innerHTML = split[2]; and so on, thanks this works.