问题描述:
JS拼接页面元素时,vue的onclick事件报错
解决方案:
<script type="text/javascript"> //新增包裹控件 CopyPackageControl: function () { var oTable = document.getElementById("tbContent"); var index = oTable.rows.length; console.log(index) if (index > 9) { layer.msg('新增包裹不能超过10个!'); return; } var newRow = oTable.insertRow(index); newRow.innerHTML = '<tr>' + '<td style="vertical-align: top"><label class="layui-form-label">包裹' + parseInt(index + 1) + ':</label></td>' + '<td> ' + '<div class="layui-input-block" style="margin-left: 0px">' + '<input type="text" name="txtExpressName" placeholder="请输入物流名称" class="layui-input">' + '<span style="float: right; margin: -42px -12px; cursor: pointer" onclick="divAlertInfoVue.doRemoveDiv(event)"><i class="layui-icon layui-icon-close-fill" style="color: #999; font-size: 24px"></i></span>' + '<input type="text" name="txtExpressNumber" placeholder="请输入物流单号" class="layui-input">' + '</div> ' + '</td> ' + '</tr>'; //事件绑定通过onclick进行绑定,而事件内容则通过定义的vue的变量divAlertInfoVue.doRemoveDiv()方法来进行指定 newRow.className = "divItemSon"; }, </script>