【问题标题】:Generating a textbox when user clicks on a gyphicon-plus当用户点击 gyphicon-plus 时生成一个文本框
【发布时间】:2016-10-30 01:05:28
【问题描述】:

有没有一种方法可以在用户单击 gyphicon-plus 时生成文本框,还是常规按钮更理想?我正在尝试创建一个座右铭,当它弹出时,用户可以单击 gyphicon-plus 按钮,它将生成一个文本框。

谢谢!

【问题讨论】:

  • 更多关于你到目前为止所取得的成就的信息会很棒。此外,有关您尝试嵌入该行为的环境的信息也会有所帮助:Webforms、MVC、Ajax 等。现在您的问题更像是“猜猜我在做什么并解决我的问题”。

标签: javascript c# jquery asp.net bootstrap-modal


【解决方案1】:

我确信您可以在控制器中添加一个函数来执行此操作,但在您操作 DOM 时使用指令被认为是最佳实践。

指令定义:

app.directive('addInput', function($compile){ 
  return {
  restrict:'E',
  template:'Click symbol to add <span ng-click="addTextBox()" class="glyphicon glyphicon-plus" aria-hidden="true"></span>',
  link: function(scope, element){
      scope.addTextBox = function () {
        var el = $compile('<input type="text">')( scope );
        element.parent().append( el );
      };
    }
  }
})

然后在你的 HTML 中

<add-input></add-input>

【讨论】:

  • 你为什么认为他在使用 Angular?
  • 哦,我以为我在角度标签部分。一定是不小心浏览了 javascript。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-29
  • 1970-01-01
相关资源
最近更新 更多