javascript 如何使 jquery datePicker 按钮图像不可点击

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3866817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 02:30:31  来源:igfitidea点击:

How to make a jquery datePicker button image unclickable

javascriptjqueryjquery-uidatepicker

提问by Farzana

I have a jquery UI datePicker in my page. I have a text box on which the date is displayed. The code is:

我的页面中有一个 jquery UI datePicker。我有一个显示日期的文本框。代码是:

$("#cal").datepicker({
    minDate: new Date(),
    defaultDate: new Date(),
    buttonImage:
        '/images/calendar.gif',
    constrainInput: false,
    closeText: 'Close',
    showButtonPanel: true,
    showButtonText: 'Choose a date', 
     buttonImageOnly : true,
    showOn : 'button'
});
$("#till").datepicker('setDate', today);

I want to disable this on some conditions. I use the following code to disable:

我想在某些情况下禁用它。我使用以下代码禁用:

 $("#cal").datePicker('disable');

It blacks out the text box but the image is still clickable. The problem is in IE, the date picker pop up comes up but does not close when the image button associated with the date picker is clicked.

它使文本框变黑,但图像仍然可以点击。问题出在 IE 中,当单击与日期选择器关联的图像按钮时,日期选择器弹出窗口出现但未关闭。

I also tried to bind a onclick function with the image to make it non-clickable. But that does not work as well.

我还尝试将 onclick 函数与图像绑定以使其不可点击。但这也行不通。

How can make the date picker image button non-clickable when the date picker is disabled.

当日期选择器被禁用时,如何使日期选择器图像按钮不可点击。

Any help would be appreciated.

任何帮助,将不胜感激。

Thanks, Farzana

谢谢,法扎娜

回答by GinoVives

I'm not sure if it will work, but you should try to change the showOn property right after the disable call.

我不确定它是否会起作用,但您应该尝试在禁用调用后立即更改 showOn 属性。

$("#cal").datepicker('disable');
$("#cal").datepicker( "option", "showOn", 'focus' );

Give it a try!

试一试!

回答by zod

why dont you hide the button itself by .hide() or adding class or style

为什么不通过 .hide() 或添加类或样式来隐藏按钮本身

or you can add style to make it disable

或者您可以添加样式以使其禁用

.addClass or .add to add css

.addClass 或 .add 添加 css

回答by Jonny Sooter

I would use .unwrap(); on the <img>to remove the <a>wrapper. That is if it's wrapped directly in the <a>tag.

我会使用 .unwrap(); 在 上<img>取下<a>包装纸。也就是说,如果它直接包装在<a>标签中。

回答by cesar andavisa

Try this:

试试这个:

$("#cal").datepicker("option", "disabled", true);

$("#cal").datepicker("option", "disabled", true);

回答by George Beier

This works for me -- gotta grab the button and disable it.

这对我有用——必须抓住按钮并禁用它。

$('#MyDatePicker').datepicker({}).next('button').attr('disabled', 'true')

$('#MyDatePicker').datepicker({}).next('button').attr('disabled', 'true')