duanjing2013 2013-07-17 17:41
浏览 72
已采纳

使用超链接通过中间函数提交表单而不是按钮是不起作用的

I want to submit a form through an 'edit(param1,param2)' function which in turn is being called in either of the two ways..

echo '<input type="button" value="DELETE" onclick="edit(\''.$key.'\',\''.$b.'\')"/>';

or

echo '<a href="list_cadmin.php" onclick="edit(\''.$key.'\',\''.$b.'\')"><span  class="bluetext">DEACTIVATE</span>';

the function edit() is something like this:

function edit(a,b) {
var answer = confirm("Do You Really want to Deactivate ?")
if (answer){
    alert(a)
document.getElementById('cid').value= a;
document.getElementById('key').value= b;
document.getElementById('fname').method='get';
document.getElementById('fname').action='samepage.php';
document.getElementById('fname').submit();
}
}

where $key and $b are number and string values respectively.

so, according to the above both should go to 'samepage.php?cid=BLAHBLAH&key=1234' on onClick. But only the input=button is working. Hyperlink is reloading without the GET parameters. How do i get the hyperlink to work?

  • 写回答

3条回答 默认 最新

  • duanjue9296 2013-07-17 17:50
    关注

    You need to prevent the href from executing by returning false from the onclick:

    echo '<a href="list_cadmin.php" onclick="edit(\''.$key.'\',\''.$b.'\'); return false;"><span  class="bluetext">DEACTIVATE</span>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条