zoukankan      html  css  js  c++  java
  • jquery获取文本框的内容

    使用jquery获取文本框的内容有以下几种:

    1.根据ID取值(id属性):

    // javascript 
    <script type="text/javascript">
       function getUserName(){
            var username= $("#username").val(); 
      }
    </script>
    // html 
    <div><input type="text" id="username"></div>
    <div><input type="button" value="commit" onclick="getUserName()"></div>

    2.根据类取值(class属性)

    // javascript 
    <script type="text/javascript">
       function getUserName(){
            var username= $(".username").val(); 
      }
    </script>
    // html 
    <div><input type="text" class="username"></div>
    <div><input type="button" value="commit" onclick="getUserName()"></div>

    3. 根据name取值,该方法也可以取其他的属性

    // javascript 
    <script type="text/javascript">
       function getUserName(){
            var username= $("input[name='username']").val(); 
      }
    </script>
    // html 
    <div><input type="text" name="username"></div>
    <div><input type="button" value="commit" onclick="getUserName()"></div>
    // javascript 
    <script type="text/javascript">
       function getUserName(){
            var username= $("input[id='username']").val(); 
      }
    </script>
    // html 
    <div><input type="text" id="username"></div>
    <div><input type="button" value="commit" onclick="getUserName()"></div>

    方法是很多的,灵活运用就好。

  • 相关阅读:
    年薪百万必备能力
    二叉搜索树
    字符串和字符串模式匹配
    2006最后寄语
    “豆瓣”式推荐
    什么是LOMO?
    大国崛起
    马季之死
    时间的价值(The Value Of Time)
    我读雅虎的“花生酱宣言”
  • 原文地址:https://www.cnblogs.com/30go/p/5704274.html
Copyright © 2011-2022 走看看