的jquery DropDownList的值设置为0 [英] jquery dropdownlist value set to 0

查看:98
本文介绍了的jquery DropDownList的值设置为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有1控制如下

<div>
        Country<br />
        @Html.DropDownListFor(model => model.CountryId, new SelectList(Model.CountriesList, "CountryId", "CountryName"), "Please select one", new { style = "width: 250px;" })
    </div>

我使用jquery清空该领域

I am using jquery to empty this field

$('#CountryId').val('');
$('#CountryId').val('0');
$('#CountryId').text('');
$("#CountryId option[value='0']").val('');
$("input[name='CountryId']").val('');

我尝试了所有的东西fabove空的DropDownList的价值,但他们没有帮助。

I tried all the fabove things to empty the value of dropdownlist but none of them helped.

另外重要的一点。
我使用我的class.So国家,可能是这个问题必须填写验证。

Also important point. I am using Required Field Validator on country in my class.So that might be the issue.

请告诉我如何下拉菜单的值设置为0;

Please tell me how to set the value of dropdown to 0;

推荐答案

请问你的选择列表中的样子..它是否有摆在首位的值= 0?
试试这个

How does your select list look like.. Does it have a value= 0 in the first place ?? Try this

$("#CountryId option:eq(0)").attr('selected', true)

勾选此 FIDDLE

选择的是第5项的下拉

修订code

有关的选择,如果没有提到的价值,只有文字是present ,然后它认为该文本作为值 ..

For the select if the value is not mentioned and only text is present then it considers the text as the value..

因此​​,这应该在你的情况下工作。

So this should work in your case

$("#CountryId").val('Please select one')​

修订FIDDLE

这篇关于的jquery DropDownList的值设置为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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