Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
115 views
in Technique[技术] by (71.8m points)

javascript - div在表单内时的div点击事件(Div click event when div is inside a form)

I have troubles to show an alert when a button (actually an input type=image object) is disabled because user should first to click on a terms checkbox.

(当用户禁用按钮(实际上是输入类型=图像对象)时,我很难显示警报,因为用户应该首先单击术语复选框。)

This is my jQuery code:

(这是我的jQuery代码:)

$('#divButton').on("click", function() {
    if ($('#buybutton').prop('disabled', true)) {
        alert('Please confirm . . .');
    }
});

And this is the HTML code:

(这是HTML代码:)

    <form>
      ...
        <div id="divButton">
            <input type="image" id="buybutton"...

        </div>
    </form>

When buybutton is disabled and I click inside divButton (over disabled button for example) nothing happens.

(当buybutton被禁用并且我在divButton内部divButton (例如,在禁用按钮上),什么也没有发生。)

I am a mobile developer trying to write JavaScript code, so be patient with me.

(我是一位尝试编写JavaScript代码的移动开发人员,所以请耐心等待。)

What am I doing wrong?

(我究竟做错了什么?)

EDIT: Debugging it on Chrome, when buybutton is disabled it is never entering inside divButton's click handler function to check

(编辑:在Chrome上调试它,禁用buybutton时,它永远不会进入divButton的click handler函数中进行检查)

if ($('#buybutton').prop('disabled', true)).

Looks like onClick event in that div be disabled.

(看起来该div中的onClick事件被禁用。)

  ask by lm2a translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

best approach is Pat Dobson's recipe, is not exactly the same than I was trying to do, but can works:

(最好的方法是帕特·多布森(Pat Dobson)的食谱,与我尝试做的不完全相同,但是可以起作用:)

Make alert window when clicking a disabled button

(单击禁用按钮时发出警报窗口)

Thanks for your help, guys ;-)

(谢谢大家的帮助;-))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...