普通网友 2016-10-30 21:09
浏览 43
已采纳

PHP和JAVASCRIPT - 如何在单击连接到每个输入字段的按钮后从多个输入字段中获取值? [关闭]

I want to create a subpage for changing the username, password, mail etc. I have 4 inputs and 4 buttons next to each input in my php file. I am wondering, how can I take the value from one of the input field after clicking on the button next to it? I want to take that values without reloading the page. What's more first click on the button changes the input field from "disabled" (in PHP) to "prop('disabled', false)" (in JAVASCRIPT). Then, you can enter something into the input field. The second click on the same button changes similarly (from "abled" to "disabled"). So I want to take the input value after SECOND CLICK on the button.

HELP ME! :<

My code: [HTML] https://i.stack.imgur.com/JE9K9.png [JAVASCRIPT] https://i.stack.imgur.com/syoKa.png

  • 写回答

1条回答 默认 最新

  • dpjjmo3079 2016-10-30 21:13
    关注

    You could do something through jQuery:

    $('.edit_profile').on('click', function(){
       // if still disabled, return;
       if ($(this).prev().is(':disabled')) return;
       // otherwise we go for value:
       var value = $(this).prev().val();
       console.log(value);
    });
    

    And please take a look for function: prev() https://api.jquery.com/prev/

    For passing your fields to php use ajax:

    $.ajax({
        type: "POST",
        url: "myphpscriptforupdate.php",
        dataType: 'html',
        data: { 
            p_year: $('#p_year').val() 
        },
        success: function(data){
            // data = response from php (the things you echoed)
            }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 react-diff-viewer组件,如何解决数据量过大卡顿问题
  • ¥20 遥感植被物候指数空间分布图制作
  • ¥15 安装了xlrd库但是import不了…
  • ¥20 Github上传代码没有contribution和activity记录
  • ¥20 SNETCracker
  • ¥15 数学建模大赛交通流量控制
  • ¥15 为什么我安装了open3d但是在调用的时候没有报错但是什么都没有发生呢
  • ¥50 paddleocr最下面一行似乎无法识别
  • ¥15 求某类社交网络数据集
  • ¥15 靶向捕获探针方法/参考文献