Javascript如何加上减去var与数字?

时间:2016-10-17 03:46:00

标签: javascript

Javascript如何加上减去var与数字?

点击id="right_arrow"时,系统会调用function right_fn(value)

但为什么功能function right_fn(value)不起作用?

https://jsfiddle.net/d21rb3mp/2/

这是HTLM代码。

<div class="left_arrow" id="left_arrow">
  <img src="http://i.imgur.com/0EDajBr.png">
</div>
<div class="right_arrow" id="right_arrow" onclick="right_fn(-200)">
  <img src="http://i.imgur.com/Zf0mFym.png">
</div>
<ul class="ul" id="ul">
  <li class="li">
    <img src="http://i.imgur.com/Ose4V9j.png">
  </li>
</ul>  

这是javascript代码

<script>
function right_fn(value) {
   document.getElementById('left_arrow').setAttribute('onclick','left_fn(value++200)')
   document.getElementById('right_arrow').setAttribute('onclick','left_fn(value+ -200)')
   document.getElementById("ul").style.transform = "translate3d(+value+px, 0px, 0px)";
}
</script>

1 个答案:

答案 0 :(得分:0)

<script>
function right_fn(value) {
  document.getElementById('left_arrow').setAttribute('onclick', `left_fn(${value + 200})`)
  document.getElementById('right_arrow').setAttribute('onclick', `left_fn(${value - 200})`)
  document.getElementById("ul").style.transform = "translate3d(+value+px, 0px, 0px)";
}
</script>