为什么我的输出未定义

时间:2015-02-09 12:41:59

标签: javascript

我似乎无法解决这个问题。我在此脚本上收到undefined而不是philadelphia输出。

<center>
<form NAME="logform">
<select SIZE="1" NAME="store">
<option name='Philadelphia' id ='Joe Smith' value='philly@store.com'>Philadelphia</option>
</select>
<br><br>
<input LANGUAGE="JavaScript" TYPE="button" VALUE="Send email"
ONCLICK="location.href = &quot;mailto:&quot; +
document.logform.store.options
[document.logform.store.selectedIndex].
value + &quot;?subject=I would like to buy the &quot; +
document.logform.store.options
[document.logform.store.selectedIndex].
name + &quot; location &quot;"
NAME="Send email">
</form>
</center>

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

而不是:

document.logform.store.options[document.logform.store.selectedIndex].name

使用:

document.logform.store.options[document.logform.store.selectedIndex].text

请注意,最后只有.name.text替换。

工作代码段:

<center>
<form NAME="logform">
<select SIZE="1" NAME="store">
<option name='Philadelphia' id ='Joe Smith' value='philly@store.com'>Philadelphia</option>
</select>
<br><br>
<input LANGUAGE="JavaScript" TYPE="button" VALUE="Send email"
ONCLICK="location.href = &quot;mailto:&quot; +
document.logform.store.options
[document.logform.store.selectedIndex].
value + &quot;?subject=I would like to buy the &quot; +
document.logform.store.options[document.logform.store.selectedIndex].text + &quot; location &quot;"
NAME="Send email">
</form>
</center>

Source