简体   繁体   English

如何使用asp.net中的JavaScript阻止用户更改DropDownList值?

[英]How to block User from changing DropDownList value using javascript in asp.net?

Hi I have a dropdownlist, I am selecting its valus from server side code. 嗨,我有一个下拉列表,我从服务器端代码中选择其值。 I don't want to allow user to change it. 我不想允许用户更改它。 Means He must not be able to change it neither by mouse click and not by keyboard. 表示他一定不能通过鼠标单击或键盘更改。 I want to handle it from Client Side. 我想从客户端处理它。 Please suggest only javascript methods. 请仅建议使用javascript方法。

Try it: 试试吧:

Jquery: jQuery:

 $(document).ready(function() {
      $("#dropdounid").prop("disabled", true);
 });

OR 要么

 $(document).ready(function() {
      $("#dropdounid").attr("disabled", true);
 });

OR 要么

Javascript Java脚本

you can disable Asp.net DropDownList using below code in javascript at client side. 您可以在客户端使用javascript中的以下代码禁用Asp.net DropDownList

document.getElementById('<%=txtActualWindSpeed.ClientID%>').disabled = true;

Edit 编辑

you can put this code inside of head tag or body tag . 您可以将此代码放在head tag or body tag

<head>
  <script>
     document.getElementById('<%=txtActualWindSpeed.ClientID%>').disabled = true;
  </script>
</head>

I hope it will helpful to you. 希望对您有帮助。

jsfiddle Demo jsfiddle演示

You can use 您可以使用

$(selector).attr('disabled',true);

jsFiddle jsFiddle

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用JavaScript将值从父asp.net下拉列表传递到弹出框中的文本框 - How to pass value from parent asp.net dropdownlist to textbox in popup using javascript 如何使用Javascript从asp.net的下拉列表中获取选定的值? - How to get selected value from dropdownlist in asp.net using Javascript? 通过javascript更改dropdownlist的值后,asp.net中dropdownlist的值消失 - Value of dropdownlist in asp.net disappears after changing the value of dropdownlist by javascript 使用Javascript在asp.net 4.5中下拉列表选择的值 - Dropdownlist selected value in asp.net 4.5 using Javascript 使用JavaScript获取下拉列表asp.net的价值? - Getting the value of a dropdownlist asp.net using javascript? 更改DropDownList项目取决于另一个DropDownList(OnChange事件)ASP.NET网页中的值 - Changing a DropDownList items Depending on a value from another DropDownList( OnChange Event) ASP.NET Webpages 我如何从Asp.Net(selectedIndexChange)中的用户获取DropDownList选定的值 - How do I get DropDownList selected value from user in Asp.Net(selectedIndexChange) 如何获取DropDownList选定的值,并将其发送到ASP.NET MVC 4中的控制器并使用JavaScript? - How can I get a DropDownList selected value and send it to the controller in ASP.NET MVC 4 and using JavaScript? 我如何在不使用javascript和asp.net选择dropdownlist值的情况下显示验证 - how can i show validation on without selecting dropdownlist value using javascript and asp.net 如何从javascript访问asp.net下拉列表选定的项目值 - How to access the asp.net dropdownlist selected item value from javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM