I have a select control, and in a javascript variable I have a text string.
(我有一个选择控件,在一个javascript变量中我有一个文本字符串。)
Using jQuery I want to set the selected element of the select control to be the item with the text description I have (as opposed to the value, which I don't have).
(使用jQuery我想将select控件的selected元素设置为具有我所拥有的文本描述的项目(而不是我没有的值)。)
I know setting it by value is pretty trivial.
(我知道按值设置它是非常微不足道的。)
eg(例如)
$("#my-select").val(myVal);
But I'm a bit stumped on doing it via the text description.
(但是通过文字描述我有点难过。)
I guess there must be a way of getting the value out from the text description, but my brain is too Friday afternoon-ed to be able to work it out.(我想必须有一种从文本描述中获取价值的方法,但是我的大脑在星期五下午也可以解决它。)
ask by DanSingerman translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…