我觉得这很容易 - 帮助 [英] I thought this would be easy - HELP

查看:73
本文介绍了我觉得这很容易 - 帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var theSel = document.forms [''price'']。elements [''cpu''];


var theVal = theSel.options [theSel.selectedIndex] .value;

var theSli = theVal.slice(1,3);



这似乎不起作用


var cpus = document.forms [''price'']。 elements [''cpu''];

var cpusx = cpus.options [cpus.selectedIndex] .value;

var cpusxd = cpusx.slice(8,10) ;


当我使用事件处理程序时


onchange =" document.forms [''price'']。value = cost( cpusxd,shpsxd)"


我收到错误消息:" cpudsx undefined

解决方案

" EJ" < jo ******** @ hotmail.comwrote in news:1174703621.570832.232670

@ o5g2000hsb.googlegroups.com:


> var theSel = document.forms [''price'']。elements [''cpu''];
var theVal = theSel.options [theSel.selectedIndex] .value;
var theSli = theVal.slice(1,3);



这似乎不起作用


var cpus = document.forms [''price'']。 elements [''cpu''];

var cpusx = cpus.options [cpus.selectedIndex] .value;

var cpusxd = cpusx.slice(8,10) ;


当我使用事件处理程序时


onchange =" document.forms [''price'']。value = cost( cpusxd,shpsxd)"


我收到错误消息:" cpudsx undefined



检查你的拼写:(cpusxd vs. cpudsx)

变量名称的限制之一你不能发音。


另外,你的onchange代码没有任何提及您想要更改值的格式为

的元素。


" EJ" < jo ******** @ hotmail.comwrote in news:1174703621.570832.232670

@ o5g2000hsb.googlegroups.com:


> var theSel = document.forms [''price'']。elements [''cpu''];
var theVal = theSel.options [theSel.selectedIndex] .value;
var theSli = theVal.slice(1,3);



这似乎不起作用


var cpus = document.forms [''price'']。 elements [''cpu''];

var cpusx = cpus.options [cpus.selectedIndex] .value;

var cpusxd = cpusx.slice(8,10) ;


当我使用事件处理程序时


onchange =" document.forms [''price'']。value = cost( cpusxd,shpsxd)"


我收到错误消息:" cpudsx undefined



放一切在一个功能。在onchange事件发生后,变量cpus,cpusx,cpusxd必须是




函数myFunc = {

var cpus = document.forms [''price'']。elements [''cpu''];

var cpusx = cpus.options [cpus.selectedIndex] .value;

var cpusxd = cpusx.slice(8,10);

document.forms [''price'']。elements [''something'']。value = cost(cpusxd,shpsxd)< br $>
}


onchange =" myFunc();"


3月24日,1 :上午10点,Jim Land< rrrrfffftttt(no)@(垃圾邮件)hotmail.com>

写道:


" EJ" < jordane ... @ hotmail.comwrote in news:1174703621.570832.232670

@ o5g2000hsb.googlegroups.com:


将所有内容放入函数中。在onchange事件发生后,变量cpus,cpusx,cpusxd必须是




谢谢,但是为什么?


你也写道:


您是否尝试将总和插入隐藏元素?


document.forms [''price'']。elements [''amount''],value = cpusxd + shpsxd;



这不产生一笔金额,或者更确切地说以下函数没有

产生一笔金额


函数总计()

{

var cpus = document.forms [''price'']。elements [''cpu''];

var cpusx = cpus.options [cpus.selectedIndex] .value;

var cpusxd = cpusx.slice(6);

var shps = document。形式[''price'']。elements [''shp''];

var shpsx = shps.options [shps.selectedIndex] .value;

var shpsxd = shpsx.slice(7);

document.forms [''price'']。elements [''amount'']。value = cpusxd + shpsxd;

}


请注意:


< select name =" cpu" ID = QUOT; CPU和QUOT; onchange =" total();">

< option selected value =" AMDx - 2500">


< select name = QUOT; SHP" ID = QUOT; SHP" onchange =" total();">

< option selected value =" 3Day - 100">


....

onchange =" total();"返回2500100


var theSel = document.forms[''price''].elements[''cpu''];

var theVal = theSel.options[theSel.selectedIndex].value;
var theSli = theVal.slice(1,3);

this doen''t seem to work

var cpus = document.forms[''price''].elements[''cpu''];
var cpusx = cpus.options[cpus.selectedIndex].value;
var cpusxd = cpusx.slice(8,10);

when I use the event handler

onchange="document.forms[''price''].value=cost(cpusxd,shpsxd)"

I get the error message: "cpudsx undefined

解决方案

"EJ" <jo********@hotmail.comwrote in news:1174703621.570832.232670
@o5g2000hsb.googlegroups.com:

>var theSel = document.forms[''price''].elements[''cpu''];
var theVal = theSel.options[theSel.selectedIndex].value;
var theSli = theVal.slice(1,3);


this doen''t seem to work

var cpus = document.forms[''price''].elements[''cpu''];
var cpusx = cpus.options[cpus.selectedIndex].value;
var cpusxd = cpusx.slice(8,10);

when I use the event handler

onchange="document.forms[''price''].value=cost(cpusxd,shpsxd)"

I get the error message: "cpudsx undefined

Check your spelling: ( cpusxd vs. cpudsx ) One of the limitations of
variable names you can''t pronounce.

Also, your onchange code lacks any mention of which element in the form
you want to change the value.


"EJ" <jo********@hotmail.comwrote in news:1174703621.570832.232670
@o5g2000hsb.googlegroups.com:

>var theSel = document.forms[''price''].elements[''cpu''];
var theVal = theSel.options[theSel.selectedIndex].value;
var theSli = theVal.slice(1,3);


this doen''t seem to work

var cpus = document.forms[''price''].elements[''cpu''];
var cpusx = cpus.options[cpus.selectedIndex].value;
var cpusxd = cpusx.slice(8,10);

when I use the event handler

onchange="document.forms[''price''].value=cost(cpusxd,shpsxd)"

I get the error message: "cpudsx undefined

Put everything in a function. The variables cpus, cpusx, cpusxd must be
evaluated after the onchange event happens.

function myFunc = {
var cpus = document.forms[''price''].elements[''cpu''];
var cpusx = cpus.options[cpus.selectedIndex].value;
var cpusxd = cpusx.slice(8,10);
document.forms[''price''].elements[''something''].value=cost(cpusxd,shpsxd)
}

onchange = "myFunc();"


On Mar 24, 1:10 am, Jim Land <rrrrfffftttt(no)@(spam)hotmail.com>
wrote:

"EJ" <jordane...@hotmail.comwrote in news:1174703621.570832.232670
@o5g2000hsb.googlegroups.com:

Put everything in a function. The variables cpus, cpusx, cpusxd must be
evaluated after the onchange event happens.

thanks, but why?

also you wrote:

Are you trying to insert the sum into the hidden element?

document.forms[''price''].elements[''amount''],value = cpusxd + shpsxd;

this does not produce a sum, or rather the following function does not
produce a sum

function total()
{
var cpus = document.forms[''price''].elements[''cpu''];
var cpusx = cpus.options[cpus.selectedIndex].value;
var cpusxd = cpusx.slice(6);
var shps = document.forms[''price''].elements[''shp''];
var shpsx = shps.options[shps.selectedIndex].value;
var shpsxd = shpsx.slice(7);
document.forms[''price''].elements[''amount''].value = cpusxd + shpsxd;
}

please note:

<select name="cpu" id="cpu" onchange="total();">
<option selected value="AMDx - 2500">

<select name="shp" id="shp" onchange="total();">
<option selected value="3Day - 100">

....
onchange="total();"returns 2500100


这篇关于我觉得这很容易 - 帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆