动态更改td标记的html

时间:2016-09-12 19:38:00

标签: javascript jquery html html-table

当触发编辑功能时,带有id" promo1"的td;更改其html以显示选项保存删除规则和取消。 cancel是一个带有onclick函数的标签,名为" cancel()"。点击后,这应该还原td标签" promo1"回到图像集。然而,当onclick来自td标签中的取消标签时,这不起作用" promo1"但是当从取消按钮触发cancel()函数时,它的作用是什么,以及为什么会发生这种情况并修复?



validator: {
        enable: function (id) {
            console.log('enable',id);
            var validator = document.getElementById(id);
            ValidatorEnable(validator, true);
        },
        disable: function (id) {
            console.log('disable',id);
            var validator = document.getElementById(id);
            ValidatorEnable(validator, false);
        }
    },

<property>
    <name>yarn.nodemanager.pmem-check-enabled</name>
    <value>false</value>
</property>

<property>
    <name>yarn.nodemanager.vmem-check-enabled</name>
    <value>false</value>
</property>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

我认为这就是你要找的东西:

&#13;
&#13;
function edit(stringID){
  console.log (stringID);
  var id = '#promo' + stringID;
  $("#promo1").html("<div style='width:200px'><a onclick='save()' style='margin-right:10px'><b>Save</b></a> <a onclick='save()' style='margin-right:10px'><b>Delete Rule</b></a> <a onclick='cancel()'><b>Cancel</b></a><div>");
}

function cancel() {
  $("#promo1").html("<img src='dist/img/editButton.png' onclick='edit(1)'>");
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table>
   <tr style="border-bottom: 1px solid #f4f4f4;">
     <td data-field="margin">15%</td>
     <td data-field="promo">Promotion Role 1</td>
     <td id="promo1" style="float:right"><img src="dist/img/editButton.png" onclick="edit(1)"></td>
   </tr>
</table>

<button onclick="cancel()">Cancel Button</button>
&#13;
&#13;
&#13;

onclick而不是<img>上使用<td>活动,并在onclick='edit(1)'中加入cancel()。其余的代码工作正常。