js实现改变文本框的value
要用js通过+和-两个button控制一个文本框的值,这一步我做到了,但是若直接在jsp页面的文本框中修改text的值之后,再去点击+和-button触发事件,就看不到文本框的值变化了(其实值变了,只是没实时显示!) 该如何解决?
/**
* 增加数量
*/
document.getElementById("add").onclick = function()
{
//文本框的节点
var count = document.getElementById("count");
if(count.value == null)
{
count.setAttribute("value", 0);
}
count.setAttribute("value", parseInt(count.value) + 1);
}
/**
* 减少数量
*/
document.getElementById("sub").onclick = function()
{
var count = document.getElementById("count");
if(count.value == null)
{
count.setAttribute("value", 0);
}
if ( parseInt(count.value) > 0)
{
count.setAttribute("value", parseInt(count.value) - 1);
}
}
/**
* 文本框值改变时出发
*/
document.getElementById("count").oninput = function()
{
alert("文本值被修改");
/*
var count = document.getElementById("count");
if(count.value == null)
{
count.setAttribute("value", 0);
}
count.setAttribute("value", parseInt(count.value));
var cno = document.getElementById("cno").firstChild.nodeValue;
var price = document.getElementById("price").firstChild.nodeValue;
var count = document.getElementById("count").value;
//responseCallback("../shoppingCart.action?cno="+cno+"&price="+price+"&count="+count);
*/
}