jq form form rendering single-box content rendering

Radio button assignment

单选按钮赋值的主要就在于一个value值和name值对应,但是单选的选中状态按钮是input标签的check(选中)属性 当newattr的属性是1的时候为true,或者当newattr的值为2的时候为true 但是后端返回的newattr只会有一个值 所以2行代码就只会生效其中之一

$("input[name=sex1][value= '1']").attr("checked", newattr === 1);
$("input[name=sex1][value= '2']").attr("checked", newattr === 2);

input content rendering

input表单渲染就一个需要注意的地方那就是input的那么值命名最好和后端返回的字段对应,解释所有可以直接渲染的input表单的内容就可以直接渲染到页面上去

// result为ajax请求获得的数据
for (var item in result) {
                // console.log(item);
                $('input[name="' + item + '"]').val(result[item]);
                // $('input[name="sex"]').val(result.sex);
                $('textarea[name="' + item + '"]').val(result[item]);
                let directionVal = result.sex === 1?'男':'女';
                let newattr = result.sex;
                $("input[name=sex1][value= '1']").attr("checked", newattr === 1);
                $("input[name=sex1][value= '2']").attr("checked", newattr === 2);

                // $('input[name="sex"]').val(directionVal)
              }

Guess you like

Origin www.cnblogs.com/wangjiahui/p/12075967.html