点击按钮不刷新页面

$('.list_r_list_button>img').click(function(e){

var id=$(this).next().val();

$.post('../shopping/cart_list.action',{'book.id':id});

$(this).next().next().children('span').html("已添加至购物车").fadeOut(2000);

});

 

<span class="list_r_list_button">

<img src='../images/buttom_goumai.gif'/>

<input type="hidden" value="${id}"/>

<span> <span></span></span>

</span>

 

.list_r_list_button>img样式选择,第一个img元素

click(function(e) 绑定点击事件

$.post('../shopping/cart_list.action',{'book.id':id}); post方式传参,

url,参数),book.id为设置的属性,id=$(this).next().val();id从隐藏表单

里面取

$(this)当前img(被绑定对象),.next(),接下来的元素,.val隐藏表单中的value

<span> <span></span></span>

父级span 下有个 空格,为了子级别span中的元素在fadeout后撑起空间

在前端开发中,点击按钮强制刷新页面有多种实现方法,以下是几种常见的方式: ### 使用 `location.reload()` 在 Vue 2 中,可以通过点击按钮调用 `location.reload()` 方法来刷新页面,此方法会重新加载当前页面,示例代码如下: ```vue <template> <div> <button @click="refreshPage">刷新页面</button> </div> </template> <script> export default { methods: { refreshPage() { location.reload(); } } } </script> ``` 这种方法简单直接,但会重新加载整个页面,包括资源和数据,适用于需要完全重置页面状态的场景[^1]。 ### 使用 `window.location.href` 可以通过设置 `window.location.href` 为当前页面URL 来实现页面刷新。代码示例如下: ```vue <template> <div> <button @click="refresh">刷新页面</button> </div> </template> <script> export default { methods: { refresh() { window.location.href = window.location.href; } } } </script> ``` 这种方式和 `location.reload()` 效果类似,同样会重新加载整个页面。 ### 前端框架中的路由刷新 在使用 Vue Router 或 React Router 等前端路由框架时,可以通过路由的方式来实现页面刷新。以 Vue Router 为例: ```vue <template> <div> <button @click="refresh">刷新页面</button> </div> </template> <script> export default { methods: { refresh() { this.$router.go(0); } } } </script> ``` `this.$router.go(0)` 会重新加载当前路由对应的页面,在单页面应用中可以避免整个页面的重新加载,只刷新当前路由视图部分。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值