我需要选择下拉列表的文本,其中id以字符串SelectId
如果id是fixedid
之类的固定ID,则可以通过
var val = $('#fixedid :selected').text();
但是,在我的情况下,我只知道该ID的一些结束文本,即SelectId
我尝试过以下代码,但失败了
$('[id$="SelectId"]').text()
我怎么能做到这一点?
答案 0 :(得分:2)
您需要在其中获取所选选项,以获取所选选项的文本内容。
$('[id$="SelectId"] :selected').text()
//-----------------^^^^^^^^^^^-------
答案 1 :(得分:2)
这应该可以获得选项。
$("select[id$='SelectId'] option:selected").text()