[英]Disable checkbox based on value by jquery handlebar.js
I have a HTML table
that includes a checkbox
with multiple selection ( handlebar
). 我有一个HTML table
,其中包含一个带有多个选项( handlebar
)的checkbox
。 I have set the value of {{status}}
which is Yes
and No
. 我已将{{status}}
的值设置为Yes
和No
。
How can I disable {{status}}
checkbox
when the value is equal to No(Function)
? 当值等于No(Function)
时,如何禁用{{status}}
checkbox
?
{{#invoices}}
<tr>
<td><input name="select_option" id="{{status}} "value="{{open_amount}}" type="checkbox"/></td>
<td style="white-space:nowrap;">{{company_code}}</td>
<td style="white-space:nowrap;">{{invoice_no}}</td>
<td style="white-space:nowrap;">{{invoice_type}}</td>
<td style="white-space:nowrap;">{{invoice_date}}</td>
<td style="white-space:nowrap;">{{due_date}}</td>
<td style="white-space:nowrap;"><font color="{{color}}">{{status}}</font></td>
<td style="white-space:nowrap;">{{open_amount}}</td>
</tr>{{/invoices}}
{{#invoices}}
function disable(){
if(document.getElementById('{{status}}') == 'Pending Process'){
document.getElementById('select_option').disabled = true;
}else{
document.getElementById('select_option').disabled = false;
}
}
{{/invoices}}
Its that work ? 它的工作?
Usually to test values I use a custom helper : 通常为了测试值,我使用自定义帮助器:
Handlebars.registerHelper('test', function(lvalue, operator, rvalue, options) {
var doDisplay = false;
var items = (""+rvalue).split("|");
var arrayLength = items.length;
for (var i = 0; (i < arrayLength); i++) {
if (operator == "eq") {
if (lvalue == items[i]) {
doDisplay = true;
}
} else if (operator == "ne") {
if (lvalue != items[i]) {
doDisplay = true;
}
} else if (operator == "gt") {
if (parseFloat(lvalue) > parseFloat(items[i])) {
doDisplay = true;
}
} else if (operator == "lt") {
if (parseFloat(lvalue) < parseFloat(items[i])) {
doDisplay = true;
}
}else if (operator == "le") {
if (parseFloat(lvalue) <= parseFloat(items[i])) {
doDisplay = true;
}
}else if (operator == "ge") {
if (parseFloat(lvalue) >= parseFloat(items[i])) {
doDisplay = true;
}
}
}
if (doDisplay) {
return options.fn(this);
} else {
return "";
}
});
You can use it like that : 你可以像这样使用它:
<td><input name="select_option" value="{{open_amount}}" type="checkbox" {{#test status 'eq' 'No(Function)'}}
disabled
{{/test}}/></td>
你可以绑定属性'disabled'。
<td><input name="select_option" {{status==='No'?'disabled':''}} value="{{open_amount}}" type="checkbox"/></td>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.