HTML点击按钮或链接不跳转只刷新页面的方法

HTML中点击按钮或链接时不跳转只刷新页面,在某些情况下还是比较实用的,下面整理些不错的示例,感兴趣的朋友可以参考下:

<input type=button value=刷新 οnclick="history.go(0)">

<input type=button value=刷新 οnclick="location.reload()">

<input type=button value=刷新 οnclick="location=location">

<input type=button value=刷新 οnclick="location.assign(location)">

<input type=button value=刷新 οnclick="document.execCommand('Refresh')">

<input type=button value=刷新 οnclick="window.navigate(location)">

<input type=button value=刷新 οnclick="location.replace(location)">

<input type=button value=刷新 οnclick="window.open('自身的文件','_self')">

<input type=button value=刷新 onClick=document.all.WebBrowser.ExecWB(22,1)>

<a href="javascript:void(0)" οnclick="history.go(0)"></a>

<a href="javascript:void(0)" οnclick="location=location"></a>
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Thymeleaf是一种用于在服务器端渲染HTML页面的模板引擎。如果你想要在Thymeleaf进行请求而不跳转页面,可以通过使用AJAX来实现。 AJAX(Asynchronous JavaScript and XML)是一种在后台与服务器进行异步通信的技术,可以在不刷新整个页面的情况下更新部分页面内容。 以下是一种使用Thymeleaf和AJAX进行请求的示例: 1. 在HTML页面,使用Thymeleaf的语法定义一个按钮或链接,绑定一个JavaScript函数来处理点击事件: ```html <button onclick="sendAjaxRequest()">发送请求</button> ``` 2. 在JavaScript函数,使用AJAX发送请求到服务器,并处理服务器返回的数据: ```javascript function sendAjaxRequest() { $.ajax({ url: "/your-url", // 替换为你的请求URL type: "GET", // 请求类型,可以是GET或POST success: function(response) { // 处理服务器返回的数据 // 可以更新页面的某个元素或执行其他操作 }, error: function(xhr, status, error) { // 处理请求错误 } }); } ``` 3. 在服务器端,根据请求URL配置相应的处理方法,可以返回JSON数据或其他格式的数据: ```java @Controller public class YourController { @GetMapping("/your-url") // 替换为你的请求URL @ResponseBody public String handleAjaxRequest() { // 处理请求逻辑,返回数据 return "Hello, AJAX!"; } } ``` 这样,当点击按钮时,会通过AJAX发送请求到服务器的指定URL,并将服务器返回的数据更新到页面的相应位置,而不会跳转整个页面。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值