【问题标题】:Jquery Mobile 1.2 Multiple Checkbox Selection IssueJquery Mobile 1.2 多个复选框选择问题
【发布时间】:2012-11-13 04:58:04
【问题描述】:

我正在编写一个基于 Jquery Mobile 1.2、Jquery 1.8.2、css 和 HTML 5 的应用程序,我需要允许用户选择多个图像并执行一个命令。

如果我不使用 jquery.mobile-1.2.0.min.js 库,则以下工作:

CSS 代码:

.image-checkbox-container input[type="checkbox"]{
    display: none;
}

.image-checkbox-container img{
    border: 0;
    margin: 4px;
 }

HTML:

<span class="image-checkbox-container">
    <input type="checkbox" name="black-box" value="1" />
<img src="dummyimage1.jpg" />
</span>
<span class="image-checkbox-container">
    <input type="checkbox" name="red-box" value="1" />
    <img src="dummyimage2.jpg" />
</span>
<span class="image-checkbox-container">
    <input type="checkbox" name="green-box" value="1" />
    <img src="dummyimage3.jpg" />
</span>

JQuery:

$('.image-checkbox-container img').live('click', function(){
    if(!$(this).prev('input[type="checkbox"]').prop("checked")){
    $(this).prev('input[type="checkbox"]').prop("checked", true);
     this.style.border = '4px solid #38A';
     this.style.margin = '0px';
}else{
        $(this).prev('input[type="checkbox"]').prop("checked", false);
    this.style.border = '0';
    this.style.margin = '4px';
}
});

一旦我将 jquery.mobile-1.2.0.min.js 库添加到代码中,它就无法正常工作了。取消选中/取消选中复选框不起作用。

我尝试使用 checkboxradio("refresh") 但没有任何运气。

任何建议将不胜感激。

谢谢

【问题讨论】:

    标签: jquery-mobile


    【解决方案1】:

    如何使用 CSS 解决方案?

    额外添加这个自定义 CSS:

     .checked {
        border : 4px solid #38A!important;
        margin : 0px!important;
     }
    

    并使用此脚本:

     <script>
      $('.image-checkbox-container img').live('click', function(){
        $this=$(this);
        if($this.hasClass('checked')===true){
          $this.removeClass('checked');
        }else{
          $this.addClass('checked');
        }
      });
      </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多