我正在研究 angularjs,我想编写一个自定义的“可编辑”指令,它可以使普通的 html 元素“可编辑”:
当用户点击它时,它会显示一个文本输入或文本区域让用户编辑内容,此外还有一个“更新”和“取消”按钮。用户可以点击“更新”按钮或按“Ctrl+enter”提交修改的内容,或点击“取消”或按“退出”取消修改。
“可编辑”签名如下所示:
<div editable
e-trigger="click|dblclick" /* use click or dblclick to trigger the action */
e-update-url="http://xxx/xxx" /* when submitting, the data will PUT to this url */
e-singleline="true|false" /* if ture, use text input, otherwise textarea */
ng-model="name"> /* the corresponding model name */
{{name}}
</div>
我在这里创建了一个现场演示:http: //jsfiddle.net/Freewind/KRduz/,你可以更新它。