【问题标题】:how to get id from between several image-buttons and write with ajax get in console.log?如何从几个图像按钮之间获取 id 并使用 ajax 写入 console.log?
【发布时间】:2018-09-18 03:30:01
【问题描述】:

我无法在 ajax 中传递按钮的 id,它显示为 MY_id undefined 作为 console.log 的输出,有人可以帮我吗?

我的问题是当我选择图像按钮然后单击发送按钮时。 imagebutton的id的值没有被捕获,如何解决?

<html>
    <input type="image" id="name-1" src="img.png"  onclick="reply_click(this.id)" class="btTxt submit "  width="100" height="130" /> 
    <input type="image" id="name-2" src="img.png" onclick="reply_click(this.id)" class="btTxt submit"  width="100" height="130" /> 
    <input type="image" id="name-3" src="img.png" onclick="reply_click(this.id)" class="btTxt submit" width="100" height="130" /> 
    <input type="image" id="name-N" src="img.png" onclick="reply_click(this.id)" class="btTxt submit" width="100" height="130" /> 
    <button type="MYbutton" id="openButton" class="btn btn-primary">MYtext</button>
        <script>
            function reply_click(clicked_id ){
                $(function() {
                    $('#openButton').on('click', function() {
                          var x = document.getElementById(clicked_id).innerHTML;
                        $.get('MYURL.com',function(data){
                            console.log('MY_id'+ x);
                        });
                    });
                });
            }
        </script>
    </html>

【问题讨论】:

标签: javascript jquery html css laravel


【解决方案1】:

这段代码解决了我的问题。

      <script>
            function reply_click(clicked_id){
                $(function() {
                    $('#openButton').on('click', function() {
                        $.get('MY_URL',function(data){
                            console.log('MY_id:  '+ clicked_id);
                        });
                    });
                });
            }
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-18
    • 2015-05-10
    • 1970-01-01
    • 2021-07-02
    • 2020-11-16
    相关资源
    最近更新 更多