【问题标题】:Asp.net Mvc Html Helper listboxFor click eventAsp.net Mvc Html Helper listboxFor click event
【发布时间】:2021-01-05 22:34:00
【问题描述】:

当用户在asp.mvc中点击时如何调用onclick 5.下面的代码不起作用

   @Html.ListBoxFor(m => Model.DepDashTaskLists[i].BusinessRuleQuestion1Answer, new MultiSelectList(slh.GetRegistrationAnswerLookup(Model.DepDashTaskLists[i].BusinessRuleQuestion1), "Value", "Text", Model.DepDashTaskLists[i].BusinessRuleAnswers), new { @onclick="somefunction()",  @id = "RuleQuestionListBoxAnswer", @class = "listbox" })

【问题讨论】:

    标签: javascript c# html asp.net-mvc


    【解决方案1】:

    有一些javascript 监听listbox 上的点击事件并获取项目文本并设置为另一个文本框的值

    @Html.ListBoxFor(x => x.ItemId, new MultiSelectList(Model.ListOfItems, "Text", "Value", Model.ItemId), new { size = 6, id = "itemsList", OnChange = "showText" })
    $(function(){
    
      $("#ItemId option").click(function () {
        var _this = $(this);
        $("#txtItem").val($(_this).text());
      });
    
    });
    

    工作样本:http://jsfiddle.net/w4sxw/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-09
      • 1970-01-01
      • 2022-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-18
      相关资源
      最近更新 更多