如何使用类名禁用Image ..使用jquery

时间:2010-06-25 03:01:25

标签: jquery

$(".ui-datepicker-trigger").attr('disabled',true);

我正在尝试禁用像这样的图像按钮..但它不起作用

但如果我做其工作

$(".ui-datepicker-trigger").hide();隐藏了,但是残疾人无法正常工作?

任何人都可以告诉我吗?

感谢

3 个答案:

答案 0 :(得分:9)

Datepicker有一个你可以使用的内置disable method,它也会禁用文本输入,如下所示:

$("#datepicker").datepicker("disable");

You can view a demo here,如果可能,您需要使用此方法,因为datepicker实际上会跟踪内部禁用的内容you can see the source code here

另一种方法是手动.unbind()来自该图片的点击,如下所示:

$(".ui-datepicker-trigger").css({opacity:'0.5',cursor:'default'}).unbind('click');

You can see a demo of that here.css()部分只是为了给它一些“禁用”样式:)

答案 1 :(得分:1)

我添加了img并使用jQuery绑定了一个单击处理程序。因此,当我禁用其他所有内容时,我也解除了单击处理程序的绑定,因此图像按钮不再起作用。无论如何,这是一个更新的工作示例。我在IE和FF中测试了这个。让我知道它是怎么回事。

 <!DOCTYPE html>
 <html lang="en">
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
   <script type="text/javascript">
     $(document).ready(function(){
       $("button").click(function(event){
         alert("you clicked the link, everything should be disabled now.");
         $(".ui-datepicker-trigger").attr('disabled',true);
         $("img.ui-datepicker-trigger").unbind('click');
       });

        // add a click handler for the img element
        $("img.ui-datepicker-trigger").bind('click', function() {alert('clicked the img');});

     });

   </script>
 </head>
 <body>
   <button class="ui-datepicker-trigger">Disable Everything</button>
   <br/>
   <input type="text" id="txt1" class="ui-datepicker-trigger" value="textbox 1"></input>

   <img class="ui-datepicker-trigger" src="calendar.jpg" alt="..." title="..." style="display: inline;">
 </body>
 </html>

答案 2 :(得分:-1)

如果有人试图隐藏日期选择器旁边的按钮,请使用以下选项:&#39; showOn&#39;:&#39;关注&#39;在调用Datepicker对象时发送给构造函数的对象中。在这里观看:http://api.jqueryui.com/datepicker/#option-showOn