.net 注意<button>按钮 表单下会刷新页面

form表单下<button>点击后会刷新页面,<input type="button">不会。

这样有时候你在用<button>按钮就需要注意了。

例如:

fun()
{
      document.getElementById("content").innerHTML = "xxxx"
}

<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr id="lct">
            </tr>
            <tr id="ms">
            </tr>
        </table>
    </div>
    <div id="content" style="display:none" >
        asdfasf
    </div>
    <button οnclick="fun()">btn</button>
    <input type="button" οnclick="fun()" value="按钮" />
    </form>
</body>
<button>btn点击后会出现页面一瞬间显示为:xxxx,但马上又变回了
asdfasf
原因:这是因为在大部分浏览器下面form表单下button点击后会提交数据刷新页面

解决办法:使用

<input type="button">
或者给button加上一个type="button"属性




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值