dsnw2651 2016-09-19 22:53
浏览 88
已采纳

如何在$ .get URL中调用this.id

I am trying to execute a javascript script but I am not sure how to do this. I usually work in PHP but for this specific thing I needed to implement some javascript. On my website I have a couple of buttons with different ID's. When a button gets pushed, a javascript will run. Inside the javascript the ID will be used to execute a php page. Right now I am using the button to delete a certain thing.

For instance, let's say I push the button with ID= 20. Then I would need the page to run the follow script:

$("button").click(function() {
    $.get("example.php?id=(this.id)");
});

As you can see I am trying to execute the page example.php?id=20 but this is somehow not working and I have no idea how I would fix this. Is there a different way to solve this problem? Btw, I use this as button

<button id="<?php echo $id; ?>" class="btn btn-primary sweet-4" onclick="_gaq.push(['_trackEvent', 'example', 'try', 'sweet-4', 'this.id']);">Test</button>

There are some more things happening here, but the main thing I want happening is getting the ID. Thanks in advance.

  • 写回答

3条回答 默认 最新

  • doubi4435 2016-09-19 22:57
    关注

    JavaScript doesn't have string interpolation (unless you use a template literal, but there's no IE support), so you will have to concatentate.

    $.get("example.php?id=" + this.id);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测