如何重置html中选定的索引下拉列表值? [英] How to reset the selected index dropdown value in html?

查看:107
本文介绍了如何重置html中选定的索引下拉列表值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在提交表单后为selecteddown设置selectedindex = 0。
我试过如下。

I need to set the selectedindex=0 for dropdown after submit form. I tried like the below.

 $("#filterByName").prop('selectedIndex', 0);
 $("#filterByName").selectedIndex=0;
$("#filterByName").get(0).selectedindex=0;

但我无法实现。请告诉我如何在提交表格后重置下拉列表。

but i am not able to acheive .please tell me how to reset the dropdown after submit form.

编辑:
$('#filterByName')[0] .selectedIndex .in我正在选择索引值。在sumit点击我设置$( '#filterByName')[0] .selectedIndex = 0然后这个语句没有设置在点击event.assigning之后显示索引0但是为什么在UI中没有显示?

$('#filterByName')[0].selectedIndex .in that i am getting selected index value.after sumit click i am setting $('#filterByName')[0].selectedIndex=0 then this statement not setting showing the index 0 after click event.assigning but why in UI is not showing ?

<span id="filterByNames"><%= Html.DropDownList("filterByName", new SelectList(Model.Names, "Name", "Name", Model.Name), 
                                new { onchange = "filterByName()" }) %></span>

请检查我的代码,让我知道如何在点击按钮后重置下拉选择的索引?

Please check my code and let me know how to reset the dropdown selected index after button click?

推荐答案

提交表格后,您可以像这样使用

After submit of form you can use like this

$('#submit').click(function(){

// after submit code

$('#filterByName option:selected').attr('selectedIndex',0);
return false;
});

这篇关于如何重置html中选定的索引下拉列表值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆