val()

功能

获取或设置指定元素的当前值。

语法

datax.attr(elm, value)

参数

  • elm
    HTMLElement对象,指定对象HTML元素
  • value
    要设置的值

范例

Example: 点击按钮时,在文本框中显示按钮的值。

<!DOCTYPE html>
<html>

<head>
    <style>
  button { margin:4px; cursor:pointer; }
  input { margin:4px; color:blue; }
    </style>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.3/require.min.js"></script>
    <script>
    require.config({
        baseUrl: "./",
        packages: [
            { name: "skylark", location: "../../../src/skylark" },
        ]
    });
    </script>
</head>

<body>
  <div>
    <button>Feed</button>
    <button>the</button>
    <button>Input</button>
  </div>
  <input type="text" value="click a button" />
    <script>
    require(["skylark/query","skylark/finder", "skylark/datax"], function(query,finder, datax) {
        query("button").click(function(){
            var text =query(this).text();
            datax.val(finder.find("input"),text)
        });
    });
    </script>
</body>

</html>