我有兩個問題。
我有一個動態網格。其中用戶單擊 AddNewRow 按鈕并生成一個帶有 jpicker 的新行。當然,每一行都有不同的 id。現在,當我為回圈中的每一行保存顏色選擇器的值時。我正在使用這種語法
$('#tblCUS tbody tr').each(function () { color = '#' $.jPicker.List[0].color.active.val('ahex'); Grid = color "?";
這只給了我第一行的值。對于每個回圈,它都會給我第一個選擇器的值。如何獲取每行顏色選擇器的值?我已經進行了幾次谷歌搜索,但只有一種語法可用。
- 在我的頁面重新加載時保存后,顏色選擇器消失了。如何使用保存在資料庫中的值顯示我的顏色選擇器?這是我的代碼
<DIV id=divsomeid style="WIDTH: 100%">
<TABLE class=display id=tblsometable style="WIDTH: 100%">
<THEAD>
<TR>
<TH class=Greyheader style="WIDTH: 5%">S.No</TH>
<TH class=Greyheader style="WIDTH: 35%">Color</TH>
<TH class=Greyheader>Action</TH></TR></THEAD>
<TBODY>
<TR class=GreyBorder id=tblSBPComments_3 pkid="3">
<TD class=GreyBorder>1</TD>
<TD class=GreyBorder><SPAN class=colorPicker id=clcColor1 value="#00ff00ff"></SPAN></TD>
<TD align=center class=GreyBorder> </TD></TR></TBODY></TABLE><BR></DIV>
頁面加載
$('#tblTable tbody tr .colorPicker').each(function (index) {
$(this).jPicker({
window: {
expandable: true,
position: {
x: 'right', // acceptable values "left",
"center", "right", "screenCenter", or relative px value
y: 'bottom' // acceptable values "top",
"bottom", "center", or relative px value
},
color: {
active: $(this).attr('value')
}
}
});
});
});
uj5u.com熱心網友回復:
每當您的頁面加載時,您可以根據span 標記的 value屬性為jPicker 的所有實體添加活動顏色,以便它顯示正確的顏色。IE :
$('#tblSBPComments tbody tr .colorPicker').each(function(index) {
$(this).jPicker({
window: {
expandable: true
},
color: {
active: $(this).attr("value") //setting active color on load
}
});
})
然后,要將這些值保存在字串或陣列中,您可以使用被迭代的行的索引并使用它來獲取活動顏色,即:
var color = []; //storing value in array
var SBPCommentsGrid = "";//or in string
//loop though table
$('#tblSBPComments tbody tr').each(function(index) {
color.push('#' $.jPicker.List[index].color.active.val('ahex') "?"); //push value in array here index will be 0, 1..etc
SBPCommentsGrid = '#' $.jPicker.List[index].color.active.val('ahex') "?";
})
作業示例
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/369610.html
上一篇:在背景關系選單中看不到屬性
下一篇:在介面或基類中宣告變數更好嗎?
