2

これは私のjsフィドルです

そしてこれがそのオリジナル版

コードは次のようなものです:

HTML:

<fieldset  class="onoffswitch">
    <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="xmonoffswitch">
    <label class="onoffswitch-label" for="xmonoffswitch">
        <div class="onoffswitch-inner">
            <div class="onoffswitch-active">Published</div>
            <div class="onoffswitch-inactive">Unpublished</div>
        </div>
        <div class="onoffswitch-switch"></div>
    </label>
</fieldset >
<div class="result"></div>

CSS:

.onoffswitch {
    position: relative; width: 182px;
    border: 0px;
    -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
    display: none;
}
.onoffswitch-label {
    display: block; overflow: hidden; cursor: pointer;
    border: 2px solid #FFF3E4; border-radius: 50px;
}
.onoffswitch-inner {
    width: 200%; margin-left: -100%;
    -moz-transition: margin 0.3s ease-in 0s; -webkit-transition: margin 0.3s ease-in 0s;
    -o-transition: margin 0.3s ease-in 0s; transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner > div {
    float: left; width: 50%; height: 41px; padding: 0; line-height: 41px;
    font-size: 20px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: normal; font-style: italic;
    -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.onoffswitch-inner .onoffswitch-active {
    padding-left: 14px;
    background-color: #F0B78B; color: #E67817;
}
.onoffswitch-inner .onoffswitch-inactive {
    padding-right: 14px;
    background-color: #F0B78B; color: #999999;
    text-align: right;
}
.onoffswitch-switch {
    width: 38px; height: 38px; margin:1.5px;
    background: #A1A1A1;
    border: 2px solid #FFF3E4; border-radius: 50px;
    position: absolute; top: 0; bottom: 0; right: 137px;
    -moz-transition: all 0.3s ease-in 0s; -webkit-transition: all 0.3s ease-in 0s;
    -o-transition: all 0.3s ease-in 0s; transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
    margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
    right: 0px;
    background-color: #E67817;
}

これは基本的に、公開済み (オン) と未公開 (オフ) の 2 つの状態を持つ切り替えボタンです。現在選択されている状態を JQuery で取得したいのですが、取得できません。このための JQuery スニペットが何であるかを誰か教えてくれますか?

4

2 に答える 2

3

The script should be :

function getStatus(){
    // will return true in case of "ON" and false in case of "OFF"
    return $("input#xmonoffswitch").is(":checked");
}

DEMO

Hope this will help !!

于 2012-10-20T10:18:00.350 に答える