当计数器大于2时隐藏按钮

时间:2016-12-15 09:34:49

标签: javascript jquery

<div id="next-button" class="text-center"> 
     button id="next_button" name="next_button" class="next-button">Next</button> 
</div>

嗨,我有这个功能,我希望当我点击按钮增加计数器,如果大于2,例如隐藏按钮..

<!-- manifest is merged, remove previous occurence of ACCESS_FINE_LOCATION -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" tools:node="remove" />

<!-- I have no idea why I need to have duplicates here, but without them, hw.location.gps is added to requirements -->
    <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
    <uses-feature android:name="android.hardware.camera" android:required="false" />
    <uses-feature android:name="android.hardware.camera.autofocus"  android:required="false" />
    <uses-feature android:name="android.hardware.location" android:required="false" />
    <uses-feature  android:name="android.hardware.screen.portrait" android:required="false"/>
    <uses-feature android:name="android.hardware.location.gps" android:required="false"/>
    <uses-feature android:name="android.hardware.camera" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.flash" android:required="false"/>
    <uses-feature android:name="android.hardware.bluetooth" android:required="false"/>
    <uses-feature android:name="android.hardware.microphone" android:required="false"/>
    <uses-feature android:name="android.hardware.location" android:required="false"/>
    <uses-feature android:name="android.hardware.location.network" android:required="false"/>
    <uses-feature android:name="android.hardware.location.gps" android:required="false"/>
    <uses-feature android:name="android.hardware.telephony" android:required="false"/>
    <uses-feature android:name="android.hardware.telephony" android:required="false"/>

2 个答案:

答案 0 :(得分:0)

你可以试试这段代码:

$(document).ready(function() {
     var clicks = 0; 
     $(".next-button").click(function(){ 
         clicks = clicks+1; 
         $('.figure').html(clicks);
         if(clicks>2){
              $(this).hide();
         }
    });
});

答案 1 :(得分:0)

你可以试试这个。适合我!!

<Button
    android:id="@+id/btn_search_back"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:background="@color/color_green"
    android:elevation="@dimen/card_elivation"
    android:text="@string/back"
    android:textColor="@color/color_white"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent" />

<ScrollView
    android:id="@+id/layout_show_response"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/btn_search_back">
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.CardView
            android:id="@+id/cv_search_for"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/margin_medium"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            card_view:cardBackgroundColor="@color/color_simple_gray">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textView"
                    style="@style/dialog_text_view"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="@string/you_ask_for"
                    android:textAllCaps="true"
                    android:textColor="@color/color_black"
                    android:textStyle="bold"
                    tools:layout_editor_absoluteY="40dp"
                    tools:layout_editor_absoluteX="15dp" />

                <TextView
                    android:id="@+id/lbl_ask_for"
                    style="@style/dialog_text_view"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:paddingBottom="@dimen/view_padding_extra_small"
                    android:text="Ask For"
                    android:textColor="@color/color_darker_gray"
                    app:layout_constraintTop_toBottomOf="@+id/textView"
                    tools:layout_editor_absoluteX="15dp" />

            </android.support.constraint.ConstraintLayout>
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/margin_medium"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cv_search_for"
            card_view:cardBackgroundColor="@color/color_simple_gray">

            <android.support.constraint.ConstraintLayout
                android:id="@+id/cl_result"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/textView2"
                    style="@style/dialog_text_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/result"
                    android:textAllCaps="true"
                    android:textColor="@color/color_black"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/lbl_reply"
                    style="@style/dialog_text_view"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:paddingBottom="@dimen/view_padding_extra_small"
                    android:text="Result"
                    app:layout_constraintTop_toBottomOf="@+id/textView2"
                    android:textColor="@color/color_darker_gray" />

                <LinearLayout
                    android:id="@+id/layout_img"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    app:layout_constraintTop_toBottomOf="@+id/lbl_reply"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    android:visibility="gone"
                    android:orientation="horizontal">

                    <ImageView
                        android:id="@+id/iv_show_img"
                        android:layout_width="@dimen/layout_width_medium"
                        android:layout_height="@dimen/layout_height_medium"
                        android:layout_gravity="center"
                        android:layout_margin="@dimen/view_margin_nano"
                        android:background="@mipmap/iv_pasted_icon" />

                    <ImageView
                        android:id="@+id/iv_show_img_icon"
                        android:layout_width="@dimen/layout_width_medium"
                        android:layout_height="@dimen/layout_height_medium"
                        android:layout_gravity="center"
                        android:layout_margin="@dimen/view_margin_nano"
                        android:background="@mipmap/iv_pasted_img" />
                </LinearLayout>


            </android.support.constraint.ConstraintLayout>
        </android.support.v7.widget.CardView>
    </android.support.constraint.ConstraintLayout>


    </ScrollView>