按照官方文檔(jqueryMobile.1.3.0)所說,拿到關於多選按鈕的代碼爲
<
fieldset
data-role
=
"controlgroup"
data-type
=
"horizontal"
data-mini
=
"true"
>
<
legend
>Checkboxes,
mini, horizontal controlgroup:</
legend
>
<
input
type
=
"checkbox"
name
=
"checkbox-6"
id
=
"checkbox-6"
>
<
label
for
=
"checkbox-6"
>b</
label
>
<
input
type
=
"checkbox"
name
=
"checkbox-7"
id
=
"checkbox-7"
checked
=
""
>
<
label
for
=
"checkbox-7"
><
em
>i</
em
></
label
>
<
input
type
=
"checkbox"
name
=
"checkbox-8"
id
=
"checkbox-8"
>
<
label
for
=
"checkbox-8"
>u</
label
>
</
fieldset
>
/*
如上所示,通常頁面,我經常用jquery.attr("checked")的屬性判斷是否爲選中狀態。可是,進過jqueryMobile的框架渲染後,這個checked的屬性只是爲了一個皮膚效果,並沒有實際選中,可以通過chrome瀏覽器查看。
網上百度谷歌了一下,發現有個帖子採用,這個方法。
$(
'input[type="checkbox"]'
).bind(
'click'
,
function
()
{
$(
this
).prop(
'checked'
).checkboxradio(
"refresh"
);
//
綁定事件及時更新checkbox的checked值
});
可能版本變化的原因,我這裏顯示沒有checkboxradio這個屬性。
看radio單屬性的api文檔,發現有val這個屬性,抱着試一試的態度,果然就是它
所以解決辦法就是,
可以通過添加val='on'屬性,然後用$(this).val('off');進行變化,從而獲得點擊狀態。
*/