简体   繁体   English

Javascript从按钮上传信息

[英]Javascript Upload informations from button

I am working on a recapitulative headband which is generated in php(phtml view file) like following : 我正在研究在php(phtml视图文件)中生成的概要头带,如下所示:

echo    "<div>
        Nom : " . $this->currentP->getName() . "</br>
        " . "Version : " . $this->currentP->getVersion() . "</br>
        " . "Date de début : " . $this->currentP->getCreation_date() . "</br>
         ...
        </div>";

I want to have a little button (with an image) next to each field which highlight the current value of each field and allow user to directly change it witout submits etc... a kind of dynamic edition on a recapitulative dashboard. 我想在每个字段旁边有一个小按钮(带有图像),以突出显示每个字段的当前值,并允许用户在未提交等情况下直接更改它...一种概述性仪表板上的动态版本。 This will give the possibility of edit the objet which is presented without making pop a window or changing the current page. 这样就可以编辑所显示的对象,而无需弹出窗口或更改当前页面。

I didn't found anything on the web, so I think this will be possible thanks to Javascript which I don't know a lot. 我没有在网络上找到任何东西,所以我认为这要归功于我不太了解的Javascript。

First of all, I don't know if I have to declare a link or a button to call the update function. 首先,我不知道是否必须声明链接或按钮来调用更新函数。 Then, what happen next ? 那么,接下来会发生什么?

Thanks for reading and your answer ! 感谢您的阅读和您的答复!

1) you add buttons for each field (or better, direct clicking on field): <div class='editableField'><span>Some text to edit</span></div> 1)您为每个字段(或更好的是,直接单击字段)添加按钮: <div class='editableField'><span>Some text to edit</span></div>

2) On field click, hide text and applie input field 2)在字段上单击,隐藏文本并应用输入字段

$('.editableField').click(function(){
    $(this).append('<input type="text" value="'+$('span', this).text()+'" class="editableInput"/>');
    $('span', this).remove(); // remove this span temporary
});

3) When .editableInput focus, use ajax call to save field values: 3)当.editableInput焦点时,使用ajax调用保存字段值:

$(document).on('focusOut', '.editableInput', function(){
    $.ajax({
       url: 'example.com/saveFieldValues.php',
       type: 'post',
       data: {fieldValue: $(this).val()},
       success: function(){
           $(this).parent().append('<span>'+$(this).val()+'</span>'); // return back old span element
           $(this).remove(); // remove unnecessary input field 
       }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM