使用javascript预先填充onclick内容

时间:2018-06-02 21:59:25

标签: javascript button

我有一个带有onclick的按钮:

<button id="startEdit" onclick="editMe('xxxx')">Edit This Record</button>

使用javascript如何预先填充和替换&#39; xxxx&#39;内容与其他东西?

我尝试过类似的事情:

<script>
document.getElementById("startEdit").innerHTML = 'newstuff';
</script>

...但这只是取代了编辑此记录&#39;部分。我希望它取代&#39; xxxx&#39;区域..

由于 戴夫

1 个答案:

答案 0 :(得分:0)

我真的不明白你想做什么,但我猜你想把一个参数传递给事件处理程序

<script>

document.getElementById("startEdit").onclick = (function(arg){

  return function editMe(){
// body of function that will be executed when you click on button here
//use 'xxxx' here as arg
  console.log(arg);
  }

})('xxxx');

</script>

相关问题