代码点火器路线按钮点击

Codeigniter route on button click

本文关键字:按钮 点火器路 代码      更新时间:2023-09-26

嗨,我正在为这个项目使用代码点火器

我有一个按钮元素如下

<div class=" pull-right" id="container">
    <button class="btn btn-info">
       <a style="text-decoration:none;color:white" href="">Guide</a>
    </button>
</div>

这个按钮元素是div的一部分,div是搜索结果之一。当我点击按钮时,如何将div的信息传递给我想要的控制器?我想要传递的信息只是div的元素id,它是"container"。

试着像一样

<button class="btn btn-info">
   <a style="text-decoration:none;color:white" href="control/method/value">Guide</a>
</button>

在你班上可以做这样的

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Control extends CI_Controller {
    public function method($value) {
        // Your value is in $value;
    }
}

[更新]动态获取父ID元素

<div class=" pull-right" id="container">
    <button class="btn btn-info" onclick="window.location='/controller/method/' + this.parentNode.id;">
       <a style="text-decoration:none;color:white">Guide</a>
    </button>
</div>

使用jQuery:

$('.btn').click(function () {
    $.ajax({
        type : "POST",
        url : 'controller/method',
        data: {id : $(this).parent().attr('id')},
        success : function(data) {}
    });
});

在您的控制器中:

$id = $this->input->post('id', TRUE);