JavaScript-an ID binding click event to make different conditional judgments?

Source: Internet
Author: User

JS Code:

 Pop-up Window Registration protocol Ms=window.parent.document.getelementbyid (' Inputzz1 ');    Ks=window.parent.document.getelementbyid (' Inputzz ');        $ (' #yes-agree '). Click (function () {console.log (MS); if (! (            Ms.getattribute (' checked ')) {console.log (123);            $ ("#inputzz1"). attr ("Checked", true);            $ ("#check-do1"). AddClass ("check-do-on"); $ ("button[title= ' Registration ']"). Removeattr ("Disabled", "disabled"). CSS ("Background-color", "#E4393C");//Enable submit button Console.lo        g (1234); } if (! (            Ks.getattribute (' checked ')) {$ ("#inputzz"). attr ("Checked", true);            $ ("#check-do"). AddClass ("check-do-on");            $ (". Pt-mid"). CSS ({"background-position": " -57px-303px"}, {"width": "175px"},{"height": "33px"});        $ ("#btnrdz"). Removeattr (' disabled ', ' disabled ');//Disable the Submit button} $ ('. Sc-model '). FadeOut (). HTML ("");    $ ('. Sc-zzc-bg '). FadeOut ();    }); $ (' #no-agree '). Click (function () {if (Ms.getattribute (' checked') {Console.log (123);            $ ("#inputzz1"). attr ("checked", false);            $ ("#check-do1"). Removeclass ("check-do-on"); $ ("button[title= ' Registration ']"). attr (' disabled ', ' disabled '). CSS ("Background-color", "#ccc");//Disable the Submit button} if (Ks.getattri            Bute (' checked ')) {$ ("#inputzz"). attr ("checked", false);            $ ("#check-do"). Removeclass ("check-do-on");            $ (". Pt-mid"). CSS ({"background-position": " -610px-583px"}, {"width": "175px"},{"height": "33px"});        $ ("#btnrdz"). attr (' disabled ', ' disabled ');//Disable the Submit button} $ ('. Sc-model '). FadeOut (). HTML ("");    $ ('. Sc-zzc-bg '). FadeOut (); });

To trigger an event HTML fragment:

      <我已阅读国广相关手册>    

Registration Protocol HTML:

不同意 同 意

Add: Registration Agreement This popup HTML is placed on the outside, and the page two places click <我已阅读国广相关手册> pop Up is the same external HTML.
Now click Agree or disagree to control the style in the two form form.

Requirement: If you click Agree or disagree with these two IDs, can JS only modify the style of the corresponding form in the form?

Reply content:

JS Code:

 Pop-up Window Registration protocol Ms=window.parent.document.getelementbyid (' Inputzz1 ');    Ks=window.parent.document.getelementbyid (' Inputzz ');        $ (' #yes-agree '). Click (function () {console.log (MS); if (! (            Ms.getattribute (' checked ')) {console.log (123);            $ ("#inputzz1"). attr ("Checked", true);            $ ("#check-do1"). AddClass ("check-do-on"); $ ("button[title= ' Registration ']"). Removeattr ("Disabled", "disabled"). CSS ("Background-color", "#E4393C");//Enable submit button Console.lo        g (1234); } if (! (            Ks.getattribute (' checked ')) {$ ("#inputzz"). attr ("Checked", true);            $ ("#check-do"). AddClass ("check-do-on");            $ (". Pt-mid"). CSS ({"background-position": " -57px-303px"}, {"width": "175px"},{"height": "33px"});        $ ("#btnrdz"). Removeattr (' disabled ', ' disabled ');//Disable the Submit button} $ ('. Sc-model '). FadeOut (). HTML ("");    $ ('. Sc-zzc-bg '). FadeOut ();    }); $ (' #no-agree '). Click (function () {if (Ms.getattribute (' checked') {Console.log (123);            $ ("#inputzz1"). attr ("checked", false);            $ ("#check-do1"). Removeclass ("check-do-on"); $ ("button[title= ' Registration ']"). attr (' disabled ', ' disabled '). CSS ("Background-color", "#ccc");//Disable the Submit button} if (Ks.getattri            Bute (' checked ')) {$ ("#inputzz"). attr ("checked", false);            $ ("#check-do"). Removeclass ("check-do-on");            $ (". Pt-mid"). CSS ({"background-position": " -610px-583px"}, {"width": "175px"},{"height": "33px"});        $ ("#btnrdz"). attr (' disabled ', ' disabled ');//Disable the Submit button} $ ('. Sc-model '). FadeOut (). HTML ("");    $ ('. Sc-zzc-bg '). FadeOut (); });

To trigger an event HTML fragment:

      <我已阅读国广相关手册>    

Registration Protocol HTML:

不同意 同 意

Add: Registration Agreement This popup HTML is placed on the outside, and the page two places click <我已阅读国广相关手册> pop Up is the same external HTML.
Now click Agree or disagree to control the style in the two form form.

Requirement: If you click Agree or disagree with these two IDs, can JS only modify the style of the corresponding form in the form?

It's a very simple thing to write, so complicated.

$('#yes-agree').on('click', function(){    // 这里判断浮层是否显示,假设$(xxx)是你的浮层    if($(xxx).is(':visible')){        // 浮层显示,修改浮层内样式        $('#inputzz1').prop('checked', true);        $("#check-do1").addClass("check-do-on");        $("button[title='注册']").prop('disabled', false);    } else {        // 浮层隐藏,修改页面内样式        $("#inputzz").prop("checked",true);        $("#check-do").addClass("check-do-on");        $("btnrdz").prop('disabled', false);    }    $('.sc-model').fadeOut().html("");    $('.sc-zzc-bg').fadeOut();});

Thank you, your hint, the code is a lot leaner, but I changed the way to do, by changing the name of the ID to do the click event binding, so that the two form action will not conflict.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.