【问题标题】:Get the val() of textarea within a foreach of php with a button in jquery使用jquery中的按钮获取php foreach中textarea的val()
【发布时间】:2015-03-17 22:51:29
【问题描述】:

使用 jquery 中的按钮在 php 的 foreach 中获取 textarea 的 val()

 $(document).ready(function(){
    $('.boton_responder').click(function(){
        var cod = $(this).attr("name");
        var texto = $('input[name="'+cod+'"]' ).val();   
        console.log(texto);  
    });
});

这是一个用 php 和 jquery 在 html 中进行评论的系统,只是当管理员登录系统时,显示所有没有答案的 cmets 并将显示一个字段 textarea 管理员将编写答案。

所以,我在这里停下来,因为在 console.log 中的 texto 显示未定义,但“cod”显示的值很好

【问题讨论】:

    标签: php jquery


    【解决方案1】:

    您的选择不正确。试试:

    var texto = $('textarea[name="'+cod+'"]').val(); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-13
      • 2019-06-16
      • 1970-01-01
      • 2020-08-16
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      相关资源
      最近更新 更多