html+js怎么实现给input的name改变值 不是改value 是改name="这里的值"!

比个例子
<td class="ha" id="ceshi"><input class="inp1" type="text" ></td>
这样 怎么实现让input根据 td里面的id改变而改变呢? 经过js变成
<td class="ha" id="ceshi"><input name="ceshi" class="inp1" type="text" ></td>
这种怎么实现?

<!doctype html>
<html>
  <head>
  <title>demo</title>
  <meta charset="utf-8"/>
  <script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>

  <style type="text/css">
  
  </style>
  <script>
    $(function(){
     $("input").click(function(){
     $("a").attr("name","123456789")
     })
    })
  </script>
  </head>
  <body>

    <a href="#">百度</a>
    <input type="button" value="点击改变超链接"/>
  </body>


</html>

我写的这个,点击按钮,改变超链接的name。

实际就是attr()方法

温馨提示:答案为网友推荐,仅供参考
相似回答