如何禁用输入类型=“image”使用jQuery的? [英] How is the correct way to disable an input type="image" using jquery?
问题描述
< input id =submit type =imagesrc =submit.jpg>
我想要做的是禁用按钮并使用不同的图像更改图像(submitGreyed。 jpg)以可视方式通知该按钮被禁用。
使用以下命令行禁用按钮:
JQuery的( #提交)ATTR( '禁用', '真')。
然后我改变图片:
JQuery的( #提交)ATTR( 'SRC', 'submitGreyed.jpg');
一旦禁用,我将提交表单:
JQuery的( #形式)提交();
第二行有一些奇怪的行为;有时工作,有时不工作。
当它工作时,按钮被禁用,图像被改变并且表单被提交;
当它不起作用时,按钮被禁用,表单被提交但图像没有改变。
我该如何解决这个问题?
这并不能完全回答你的问题,但我希望它有帮助: ,它应该是 disabled =disabled
所以使用这个:
jQuery的( #提交)ATTR( '禁用', '禁用')。
我不确定您的灰色按钮是什么样子,但您可以尝试使用不透明度:
$ b
jQuery(#submit)。attr('disabled','disabled').css('opacity',0.5 );
更新我无法复制问题,所以这里是我的建议:
使用图像的绝对路径而不是相对图像,并同时设置两个属性(虽然一个接一个地设置并不会改变我的测试):
jQuery(#submit)。attr({
disabled:'disabled',
src:'/images/submitGreyed.jpg'
});
由于在测试中我使用了完整路径,可能会影响它。
With jQuery, I'm trying to disable an input field like this:
<input id="submit" type="image" src="submit.jpg">
What I would like to do is disabling the button and change the image with a different image (submitGreyed.jpg) to visually notify that button is disabled.
With the following line I disable the button:
JQuery("#submit").attr('disabled','true');
then I change the image with:
JQuery("#submit").attr('src','submitGreyed.jpg');
and once disabled I submit the form with:
JQuery("#form").submit();
The second line has some weird behaviour; sometimes works and sometimes doesn't.
When it works, button is disabled, image changed and form is submitted; when it does not work, button is disabled, form is submitted but image is not changed.
How can I solve this?
This doesn't answer your question exactly, but I hope it helps:
First, it should be disabled="disabled"
so use this:
jQuery("#submit").attr('disabled','disabled');
And I am not sure what your grayed out button looks like, but you could try just using opacity:
jQuery("#submit").attr('disabled','disabled').css('opacity',0.5);
Update I couldn't replicate the problem, so here is my suggestion:
Use an absolute path to the image instead of a relative one, and set both attributes at the same time (Though setting one after the other didn't change my test):
jQuery("#submit").attr({
disabled: 'disabled',
src: '/images/submitGreyed.jpg'
});
Since in my test I used a full path, that might have affect it a bit.
这篇关于如何禁用输入类型=“image”使用jQuery的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!