单选按钮如何使用函数中确定的值预先选择值
radio button how to pre select value with the value determined in the function
>我有一个这样的方法:
$('.officeapprovalspan').click(function () {
var invoicelineid = $(this).data("invoicelineid");
var approval = $(this).data("approval");
$(this).replaceWith('<input type="radio" name="variety" value="null" class="radioapproval" data-invoicelineid=' + invoicelineid + ' /><span class="pleaseapprove">Please Accept</span><br >' +
'<input type="radio" name="variety" value="false" class="radioapproval" data-invoicelineid=' + invoicelineid + ' /><span class="onhold">On Hold</span><br >' +
'<input type="radio" name="variety" value="true" class="radioapproval" data-invoicelineid=' + invoicelineid + ' /><span class="accepted">Accepted</span>');
$(document).on('change', '.radioapproval', radiohandler);
});
所以,我有三个单选按钮。我想要实现的是基于变量批准的值预选相应的单选按钮。审批的值为 null、false 或 true。
有人可以告诉我你会怎么写这个,因为我正在用替换添加它
尝试使用 .html()
:
var invoicelineid = $(this).data("invoicelineid");
var approval = $(this).data("approval");
$(this).html(
'<input type="radio" name="variety" value="null" class="radioapproval" data-invoicelineid=' + invoicelineid + ' /><span class="pleaseapprove">Please Accept</span><br >' +
'<input type="radio" name="variety" value="false" class="radioapproval" data-invoicelineid=' + invoicelineid + ' /><span class="onhold">On Hold</span><br >' +
'<input type="radio" name="variety" value="true" class="radioapproval" data-invoicelineid=' + invoicelineid + ' /><span class="accepted">Accepted</span>'
)
.find(':radio[name="variety"][value="' + approval + '"]')
.prop('checked', true);
例如,如果approval
变量的值为 true
则将选择最后一个单选按钮。
相关文章:
- 选择时使用jQuery克隆HTML DIV
- HTML使用选择表单更改输入选择(可能使用JQuery?)
- 默认按表列选择选项(使用Javascript)
- Accordion选择在使用jquery点击其中一个时无法正常工作
- 试图创建一个具有2“;数量;选择器使用html、javascript
- 允许日期选择器使用文本输入字段
- 日期选择器使用所有字段的下拉菜单JavaScript和JQuery W/O日历
- 在链接选择上使用jQuery添加/删除类
- 选择除使用 JavaScript 的文本框之外的所有文本框
- 在 HTML 中选择中使用 Vue.js 和 Minimalect 显示默认值
- 高如何选择要使用 javascript 显示的范围?.
- 有选择地使用 MathJax 渲染方程
- 如何使用类选择器使用 Jquery ScrollTo() 将页面滚动到元素
- 如何获取 HTML 选择以使用 JavaScript 显示所选值
- 反应构建选择输入使用 for 循环
- Angularjs 2:在离子选择离子 2 中选择不使用选定值更新
- AngularJs:选择在使用ng-repeat时不显示任何选项的下拉列表
- jQuery选择器使用正则表达式(或其他东西)
- 为什么日期选择器使用 Jquery 日期选择器仅显示 20 年的选项
- 选择“JS使用数组作为源”