Javascript 对表行的每个按钮执行jQuery逻辑

Javascript 对表行的每个按钮执行jQuery逻辑,javascript,jquery,html,Javascript,Jquery,Html,我有一个包含以下列的公司表:id,company\u name,select\u按钮 当单击公司行的选择按钮时,我想要: 此行的按钮将被禁用,并且 我想让它提醒这一行的公司名称 我不知道如何在每个按钮都指向具有特定id的特定行的情况下完成此操作。 有人能给我一些建议吗 我要给每个按钮一个id吗?如果是,我该怎么办?我的以下逻辑不起作用: <input type='button' class="button_<?php echo $company->id ?>" />

我有一个包含以下列的公司表:
id
company\u name
select\u按钮

当单击公司行的
选择按钮时,我想要:

  • 此行的按钮将被禁用,并且
  • 我想让它提醒这一行的公司名称
  • 我不知道如何在每个按钮都指向具有特定id的特定行的情况下完成此操作。
    有人能给我一些建议吗

    我要给每个按钮一个id吗?如果是,我该怎么办?我的以下逻辑不起作用:

    <input type='button' class="button_<?php echo $company->id ?>" />
    
    <script>
        $(document).ready(function(){
            $(':button_<?php echo $company->id ?>').click(function(){
                alert('<?php echo $company->company_name; ?>');
                $(':button_<?php echo $company->id ?>').prop("disabled",true);             
        });
    </script>
    
    HTML

    您可以使用jQuery保存HTML元素上的数据,并在以后检索:

    <input type="button" class="my-btn" id="button_1" value="button #1" />
    <input type="button" class="my-btn" id="button_2" value="button #2" />
    <input type="button" class="my-btn" id="button_3" value="button #3" />
    
    $(document).ready(function() {
        $('#button_1').data('msg', 'text you need to alert for button #1');   
        $('#button_2').data('msg', 'text you need to alert for button #2');
        $('#button_3').data('msg', 'text you need to alert for button #3');
    
        $('.my-btn').on('click', function(){
            alert($(this).data('msg'));
            $(this).prop("disabled",true);             
        });
    });
    
    
    $(文档).ready(函数(){
    $(“#按钮#1”)。数据('msg','text您需要提醒按钮#1');
    $(“#按钮"2')。数据('msg','text您需要为按钮#2'发出警报);
    $(“#按钮#3”)。数据('msg','text您需要提醒按钮#3');
    $('.my btn')。在('click',function()上{
    警报($(this.data('msg'));
    $(this.prop(“disabled”,true);
    });
    });
    
    注意:您可能需要将上述内容更改为
    id=“button#”value=“button#”


    查看。

    非常感谢您的回答。是的,我仍然像做$('#button')一样被卡住了。没有php的情况下单击(f…),然后我让它发出一个简单的“某物”警报,但是当我在“$('#button')中添加php代码时。单击(f…)它不会发出简单的“某物”警报-我两次都相应地更改了html中的输入id。
    $(document).ready(function(){
        $('.button').click(function(){
            alert($(this).val());
            $(this).prop("disabled",true);             
    });
    
    <input type="button" class="my-btn" id="button_1" value="button #1" />
    <input type="button" class="my-btn" id="button_2" value="button #2" />
    <input type="button" class="my-btn" id="button_3" value="button #3" />
    
    $(document).ready(function() {
        $('#button_1').data('msg', 'text you need to alert for button #1');   
        $('#button_2').data('msg', 'text you need to alert for button #2');
        $('#button_3').data('msg', 'text you need to alert for button #3');
    
        $('.my-btn').on('click', function(){
            alert($(this).data('msg'));
            $(this).prop("disabled",true);             
        });
    });