按钮不使用表单/提交按钮和更新信息

时间:2017-07-17 09:48:47

标签: javascript

这里新的。目前迷失在我的节目中。我似乎无法使用页面中的按钮。按下任意两个按钮后,我想更新我的内容。这就是我坚持的地方:

var value = 1; //set default to 1
var button1 = document.getElementById("button1");
var button2 = document.getElementById("button2");

button1.onClick = function()
{
	value = 1;
}

button2.onClick = function()
{
	value = 2;
}
<button type="button" class="btn btn-default btn-md" value="1" id="button1">Store 1</button>
<button type="button" class="btn btn-success btn-md" value="2" id="button2">Store 2</button>

<!-- the following lines are under td of a table -->
<tr>
  <script type="text/javascript">
    if (value == 1)
    {
      coolerName = "Corsair H100i v2";
      coolerPrice = 5440;
    }
    if (value == 2)
    {
      coolerName = "Corsair H100i v2";
      coolerPrice = 5450;
    }
    document.write("<td>" + coolerName + "</td>");
    document.write('<td id="alignRight">');
    if (coolerPrice > 0)
    {
      document.write(coolerPrice.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'));
    }
    else
    {
      document.write(coolerPrice.toFixed(0).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'));
    }
    document.write('</td>');
  </script>
</tr>

我需要在这里做AJAX,还是JScript好?

0 个答案:

没有答案