我需要从javascript中获取所选选项的值,有没有人知道如何获取所选值或文本,请告诉我们如何为它编写函数。
这里的截图: Respondent page 。从这个截图我想选择"期间名称"将在" Group Name"。
中自动将相应的值从他选择的时间段中移出这里是视图页面create.cshtml
<a href="#" class="button-blue button-text a-button" id="lnkAddResp" style="width:100px">@ViewRes.Language.multirater_respondent_add</a>
@foreach (var p in ViewBag.surveygroups)
{
<input type="hidden" class="hiddenSurveyGroups" name="hiddenSurveyGroups" id="surveygroups" value="@p.Value" />
}
控制器页面:
public ActionResult Create(int PeriodID = 0)
{
var ParentQry = from d in db.Periods
join sc in db.MultiRaterSurveyPeriods on d.PeriodID equals sc.PeriodID
where d.StartDate < DateTime.Now && d.EndDate > DateTime.Now && sc.StartDate < DateTime.Now && sc.EndDate > DateTime.Now
orderby d.PeriodID
select new {PeriodID = sc.MultiRaterSurveyPeriodID, PeriodName = d.PeriodName };
var GroupResp = from d in db.MultiRaterSurveyGroups
join sc in db.RelationBetweenMRSPeriodMRSGroups on d.MultiRaterSurveyGroupID equals sc.MultiRaterSurveyGroupID
where d.StartDate < DateTime.Now && d.EndDate > DateTime.Now && sc.StartDate < DateTime.Now && sc.EndDate > DateTime.Now
orderby d.MultiRaterSurveyGroupID
select new { MultiRaterSurveyGroupID = d.MultiRaterSurveyGroupID, MultiRaterSurveyGroupName = d.MultiRaterSurveyGroupName, MultiRaterSurveyPeriodID = sc.MultiRaterSurveyPeriodID };
ViewBag.PeriodID = new SelectList(ParentQry, "PeriodID", "PeriodName");
ViewBag.surveygroups = new SelectList(GroupResp, "MultiRaterSurveyGroupID", "MultiRaterSurveyGroupName");}
JS页面:如何在js上设置,根据我选择的特定时期名称显示值?
var linkresp3 = location.href;
if (linkresp3.indexOf('MultiRaterSurveyRespondent/Create') != -1) {
var peridresp = $("#PeriodID").val();
var selectsurveygroups = $("#surveygroups").val('p.Value');
var groupname = $("#GroupName_" + k);
$(groupname).empty().append($('<select id="surveygroups" name="surveygroups"><option value="0" selected="selected">----- select -----</option><option value="' + $("#surveygroups").val() + '"</option></select>'));
var opts = selectsurveygroups.filter(".Group" + peridresp);
$.each(opts, function (i, j) {
$(j).appendTo('#GroupName_' + k);
});
$("#GroupName_" + k).val(groupname);
示例:将出现选择2015:A,B,C和选择2016仅显示B,B,D(已在DB上设置)