HTML下拉选择值 [英] HTML Dropdown selection value

查看:124
本文介绍了HTML下拉选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

I have the following code:

<select>
<option value="blablabla">Test</option>
<!-- ... -->
</select>

但是我想知道是否可以将option标签的value属性设置为引用一个对象(在JavaScript中)。

But I want to know if I can set the "value" attribute of the option tag, as a reference to an object (in javascript).

推荐答案

选项值必须是字符串可以是一个数字)。

The option value must be a "string" (that string can be a number).

你想做的事情有点不寻常,但可以完成(但我认为有更好的方法来实现你想做的事情) ...你可以序列化你的对象并将其设置为值,但这将是奇怪的。

What you want to do is a bit unusual but can be done (but I think there are better ways to achieve what you want to do)... You could serialize your object and set it in the value but that would be odd.

您也可以将这些引用索引到数组中,然后将其索引设置为该选项的价值......

You could also index these references in an array and then set it's index in the value of the option...

这篇关于HTML下拉选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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