douci4026 2013-05-28 15:43
浏览 71
已采纳

按钮onclick()事件不应该打开链接

This may sound weird, but I want to have a button with a link that does not open when the users clicks it:

<a href="http://mysite.nl/test.php?value=snow"> click</a>

I want to do this because this link has PHP values to recreate the page. The button is on with a new background colour.

I can't just use

document.body.style.backgroundColor='Snow'

because the page auto reloads and I want the colour to stay 'snow' even when the page reloads.

Can this be done? Are there better ways to permanently change the style by the click of a button?

  • 写回答

5条回答 默认 最新

  • du20150401 2013-05-28 15:47
    关注

    You can use php SESSION for this

    $_SESSION['color']='snow';
    

    and take the value from from session by each reload. And use preventDefault() for prevent the link redirection by using javascript

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失