我有这样的:不能在一个onchange分配字符串到另一个字符串=()函数
<select id="prio" class="w60">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
如果我选择另一个值,onchange = function()
被称为:
var prio = document.getElementById('prio');
var string1 = "Hello";
var string2 = "";
prio.onchange = function()
{
prioIndex = prio.options[prio.selectedIndex].text;
switch (prioIndex)
{
case '1': prioIndex = " my Friend";
break;
case '2': prioIndex = " my Sister and Brother";
break;
case '3': prioIndex = " my Mom and Dad";
break;
}
alert(prioIndex);
string2 = prioIndex;
}
alert(string2);
警报函数内部工作正常,但他不会分配新的字符串。
alert(string2)
显示string2(未定义)。
我想使用string2
以外的函数。但我不能,因为它从来没有分配过。但我不知道为什么。
比方说,我想在另一个平变化的功能使用string2
...
var string3;
news.onchange = function()
{
string3 = string2.concat(' how are you');
alert(string3);
}
并将其分配给string3
。如果我想使用string3
以外的交换功能,它是undefined
。