2015/09/08

jQuery 修改id或名稱


程式碼:
<!DOCTYPE html>
<html>
<head>
 <meta charset="utf8">
 <title>hi</title>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
 <script type="text/javascript">
  function myClick () {
   var myText = $('#demo');

   //更改id
   myText[0].id = "id";

   //更改name
   myText[0].name = "name";

  }
 </script>
</head>
<body>
 <input type="text" id="demo" name="demo">
 <button onclick="myClick();">Change</button>
</body>
</html>


執行前:



執行後: