<html>
<body>
Search: <input type="search" id="mySearch" name="googlesearch">
<p>点击按钮显示或修改搜索字段 name 属性的值。</p>
<button onclick="display()">显示名称</button>
<button onclick="change()">修改名称</button>
<script>
function display() {
var x = document.getElementById("mySearch").name;
alert("搜索字段名称为: " + x);
}
function change() {
var x = document.getElementById("mySearch").name = "newSearchName";
alert ("名称修改为: " + x);
}
</script>
</body>
</html>