<select name="province" lay-filter="province">
<!--
<option value="">请选择省</option>
<option data-href="https://daohang.qq.com/" value="浙江" selected="">浙江省</option>
<option data-href="https://www.layui.com/" value="411000">江西省</option>
<option data-href="https://www.baidu.com/" value="你最喜欢的老师">福建省</option>
-->
</select>
//数据填充
$.ajax({
type: "get",
url: "js/data.json",
data: { parentId: id },
success: function(data) {
console.log(data);
var array = data.rows || data;
var str = "";
for (var index = 0; index < array.length; index++) {
var element = array[index];
str +='<option data-href="' + element.AREA_ID + '" value="' + element.AREA_ID +'">' +
element.AREA_NAME + "</option>";
}
$("select[name='province']").html(str);
form.render("select"); //刷新select选择框渲染
}
});
//事件监听
form.on("select(province)", function(data) {
//获取自定义属性值
var datahref = $(data.elem).find("option:selected").attr("data-href");
console.log(datahref);
});
来源:oschina
链接:https://my.oschina.net/liyoungs/blog/3190549