如何在jquery中选择元素?

时间:2017-06-05 08:13:42

标签: jquery

我是这种编程语言的初学者。请原谅。

如何在JQuery中选择元素?我的代码出了什么问题? SOmeone帮助我。

    <!DOCTYPE html>
    <html>
         <head>
         <title></title>
         <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
         </head>
    <body>
    <input type="password">

    <script type="text/javascript">
         $(document).ready(function(){

         $('input[type=password]').attr({
              name: 'pass'
              style: [
                  color: 'blue',
                  font-size: '20px'
              ],
            });
        )};
    </script>

3 个答案:

答案 0 :(得分:2)

使用.css()作为样式属性

$(document).ready(function() {

  $('input[type=password]').attr({
    name: 'pass'
  }).css({
    "color": "blue",
    "font-size": "20px"
  });

});
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<input type="password">

答案 1 :(得分:1)

看起来你打算写:

&#13;
&#13;
$(document).ready(function() {
  $('input[type=password]').attr({
    name: 'pass',
    style: 'color: blue; font-size: 20px'
  });
});
&#13;
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<input type="password">
&#13;
&#13;
&#13;

答案 2 :(得分:0)

    <!DOCTYPE html>
            <html>
                 <head>
                 <title></title>
                 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
                 </head>
            <body>
            <input type="password">

            <script type="text/javascript">
                 $(document).ready(function(){

                 $('input[type=password]').attr("name","pass").css({"color":"blue","font-size":"20px"});
               });
            </script>
</body>
</html>