小编Yor*_*llo的帖子

如何使用 ng-click 获取 DOM 元素

我有一些元素,如:

<button ng-click="weirdFunction()">Pretty Button</button>
Run Code Online (Sandbox Code Playgroud)

和控制器中的功能:

$scope.weirdFunction = function(element) {
 console.log(element);
}
Run Code Online (Sandbox Code Playgroud)

在控制台日志中,我想接收这个 DOM 元素。我试图通过几种方式做到这一点:

  1. <button ng-click="weirdFunction()" ng-model="button">Pretty Button</button>

    $scope.weirdFunction = function() { console.log($scope.button); }

  2. <button ng-click="weirdFunction(button)" ng-model="button">Pretty Button</button> $scope.weirdFunction = function(elem) { console.log(elem); }

  3. <button ng-click="weirdFunction($element)">Pretty Button</button> $scope.weirdFunction = function(elem) { console.log(elem); } 但所有的尝试都失败了。我错在哪里?如何获取点击的元素?

javascript angularjs

4
推荐指数
1
解决办法
9080
查看次数

使用带有最大宽度的空白 nowrap

我想制作一些带有分隔线的自定义标题。最大宽度文本我设置为 40%,行分隔符显示在文本后面。主要思想是,如果文本少于 40%,则行从文本结束处开始,但如果文本大于 40%,则会换行。

不幸的是,如果我不使用white-space: nowrap;文本 - 分隔线会使我的文本崩溃,但当我使用时white-space: nowrap max-width: 40%则不起作用。我哪里错了?

更新。我只想当文本很大时 - 它填充所有最大宽度,并且分隔线从 40% 开始,但是当文本很小时 - 分隔线从文本末尾开始,而不是从 40% 开始。

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<!-- first example -->
              <div class="addition-hr">
                <table style="width: 100%; margin-bottom: 5px">
                  <tr style="width: 100%">
                    <td style="max-width: 40%; margin-top: 30px; margin-bottom: 30px; padding: 0 15px 0 15px; white-space: nowrap;">
                      <span style="position: relative"><b>Lorem ipsum dolor sit amet</b></span>
                    </td>
                    <td style="width: inherit; display: table-cell"> …
Run Code Online (Sandbox Code Playgroud)

html css html-table

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

angularjs ×1

css ×1

html ×1

html-table ×1

javascript ×1