在 MooTools 中使用 getSelected
我是 JS 和 Mootools 的新手,在 Mootools 1.3.2 中使用 getSelected() 时遇到了一个非常有趣的错误。 我看过其他具有类似代码的帖子,但我还没有成功的。我正在使用 getSelected 尝试获取选项的值,但由于某种原因,我的浏览器根本没有调用它。
这是 HTML
<select id="id_method" name="method">
<option selected="selected" value="">---------</option>
<option value="Au">Auction (Best Price Wins)</option>
<option value="Fi">Fixed Price</option>
<option value="Fr">Free Item/Donation</option>
<option value="Mu">Multiple Items and Prices</option>
<option value="No">No Price Displayed</option>
<option value="Tr">Trade</option>
</select>
这是 JS
window.addEvent('domready', function() {
...
$('id_method').addEvent('change', function() {
alert(this.getSelected().selection[0].value);
});
});
这是我在 jsfiddle 中放入的尝试: http://jsfiddle.net/jNYud/
我知道这可能是一个非常愚蠢的问题,但我希望得到一些帮助。谢谢!
I'm new to JS and Mootools and I've been having a really funny error using getSelected() with Mootools 1.3.2. I've looked at other posts that have similar code, but I haven't been successful. I'm using getSelected to try and get the value of an option and for some reason, my browser simply isn't calling it.
Here's the HTML
<select id="id_method" name="method">
<option selected="selected" value="">---------</option>
<option value="Au">Auction (Best Price Wins)</option>
<option value="Fi">Fixed Price</option>
<option value="Fr">Free Item/Donation</option>
<option value="Mu">Multiple Items and Prices</option>
<option value="No">No Price Displayed</option>
<option value="Tr">Trade</option>
</select>
Here's the JS
window.addEvent('domready', function() {
...
$('id_method').addEvent('change', function() {
alert(this.getSelected().selection[0].value);
});
});
Here's my attempt at putting in in jsfiddle: http://jsfiddle.net/jNYud/
I know this is probably a really silly question, but I'd appreciate some help. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用 getSelected() 的结果返回一个数组,纯粹而简单。所以你只需要查看该数组的第一个元素。因此,将您的警报替换为以下警报:
The result of calling
getSelected()
returns an array, pure and simple. So you just need to look at the first element of that array. So replace your alert with this one: