我的select语句有一个更改,我可以访问this.value
等属性
$('select[name="ceremony"]').on('change', function(){
console.log( this )
});
我需要以某种方式获取所选的值文本。 this.options
内容都不起作用
我得到它我想像这样显示它:
$('.title').html( <here> )
答案 0 :(得分:1)
要获取所选选项文字(不是值),您可以使用CREATE VIEW AS
SELECT GroupKey
, DATEPART(yyyy, sale.[Date]) year
, DATEPART(m, sale.[Date]) month
, null as Description
, sum(Volume) as GroupVolume
, sum(Value) as GroupValue
FROM dbo.dim_Group grp
LEFT JOIN dbo.fact_Sales sale on sale.GroupKey = grp.[Key]
group by GroupKey
, DATEPART(yyyy, sale.[Date])
, DATEPART(m, sale.[Date])
:
$('option:selected',this).text()
&#13;
$('select').on('change',function(){
console.log($('option:selected',this).text());
});
&#13;
答案 1 :(得分:0)
this.value
获取当前选定的选项
$('select[name="ceremony"]').on('change', function(){
$('.title').html(this.value)
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1 class="title"></h1>
<select name="ceremony">
<option>hi</option>
<option>there</option>
</select>
&#13;
答案 2 :(得分:0)
:selected
$.text
获取可见文本。$.val
获取选项的值。
$('select').on('change',function(){
var $selected = $(this).find(":selected");
$('.title').html("Text: " + $selected.text() + ", Value: " + $selected.val());
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select>
<option value="1">Opt 1</option>
<option value="2">Opt 2</option>
<option value="3">Opt 3</option>
</select>
<h1 class="title">
</h1>
&#13;