我似乎无法解决这个问题。我在此脚本上收到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 = "mailto:" +
document.logform.store.options
[document.logform.store.selectedIndex].
value + "?subject=I would like to buy the " +
document.logform.store.options
[document.logform.store.selectedIndex].
name + " location ""
NAME="Send email">
</form>
</center>
感谢您的帮助。
答案 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 = "mailto:" +
document.logform.store.options
[document.logform.store.selectedIndex].
value + "?subject=I would like to buy the " +
document.logform.store.options[document.logform.store.selectedIndex].text + " location ""
NAME="Send email">
</form>
</center>