第一次点击无法触发点击事件
<div class="contain" id="changeDiv"><div class="edit-div" contenteditable="true"></div></div>-----------------------------------------------------------function change(){var changeDiv=$("#changeDiv")if(data[1].id==1101){var $div=$("<div class=\"edit-div\" onclick=\"simpleDate(this)\" contenteditable=\"true\"></div>");// $div.click()//初始化点击事件changeDiv.html($div)}else if(data[1].id==1109){var $div=$("<div class=\"edit-div\" onclick=\"rangeDate(this)\" contenteditable=\"true\"></div>");// $div.click()//初始化点击事件changeDiv.html($div)}else if(data[1].id==1110){changeDiv.html("<div class=\"edit-div\" contenteditable=\"true\"></div>")}}------------------------------------------------------------layui.use('laydate', function(){var laydate = layui.laydate;//时间选择器window.rangeDate = function (that){var routeTime = {type: 'datetime',range: true};routeTime.elem = that;laydate.render(routeTime);}window.simpleDate = function (that){var routeTime = {type: 'datetime',};routeTime.elem = that;laydate.render(routeTime);}});
如果在变更时初始化点击事件"$div.click()",却又会在初始化时触发点击事件
解决办法是将onclick事件修改为onfocus事件
οnfοcus=\"simpleDate(this)\"