我希望echo
button's
value
field
中的{capnum}值<script type="text/javascript">
var capnum = 0;
function add()
{
capnum++;
document.getElementById('display').innerHTML = capnum;
}
</script>
<button name="subject" type="submit" value="<script> document.write(capnum) </script>" onclick="showUser(this.value);add()" >NEXT</button>
...我该怎么做?
我的代码在这里 -
SELECT 1=1
答案 0 :(得分:0)
试试这个,
<script type="text/javascript">
var capnum = 0;
function add()
{
capnum++;
document.getElementById('display').innerHTML = capnum;
}
</script>
<button id="display" name="subject" type="submit" value="<script> document.write(capnum) </script>" onclick="showUser(this.value);add()" >NEXT</button>
答案 1 :(得分:0)
只需添加id =&#34;显示&#34;到你的按钮。 我还将.innerHTML更改为.value,因为您的帖子表示您想要更改其值。
<script type="text/javascript">
var capnum = 0;
function add()
{
capnum++;
document.getElementById('display').value = capnum;
}
function showUser(i) { // i just added this to test if value was changing
alert(i);
}
</script>
<button id="display" name="subject" type="submit" value="" onclick="add(); showUser(this.value);" >NEXT</button>
当我测试确保它有效时,我也在add()之后移动了showUser
答案 2 :(得分:0)
setAttribute
javascript
<button name="subject" id="myId" type="submit" onclick="add(this.value);add()" >NEXT</button>
<script type="text/javascript">
var capnum = 0;
function add()
{
capnum++;
document.getElementById('myId').setAttribute('value', capnum);
}
</script>