.val() works on input elements (or any element with a value attribute?) and .text() will not work on input elements.  .val() gets the value of the input element -- regardless of type. .text() gets the innerText (not HTML) of all the matched elements:

.text()

The result is a string that contains the combined text contents of all matched elements. This method works on both HTML and XML documents. Cannot be used on input elements. For input field text use the val attribute.

.val()

Get the content of the value attribute of the first matched element

Difference between val() and text()的更多相关文章

  1. jquery val() and text().

    .val() works on input elements (or any element with a value attribute?) and .text() will not work on ...

  2. jQuery中val()、text()、html()之间的差别

    一.括号里没有值时表示取值    val获取表单中的值: text获取对象中的文本内容,不包含html标签: html获取对象中的内容,包括html标签 <!DOCTYPE HTML> & ...

  3. [转载]jQuery中的html,val,text区别

    在jquery中 text() 返回目标元素所包含的所有文本内容,注意不包含html标签 alert($("#shuru").text()); 1 html() 返回目标元素所包含 ...

  4. val();html();.text()区别 setInterval与setTimeout的区别

    val();html();.text()区别   对于innerHTML 属性,几乎所有的元素都有innerHTML属性,它是一个字符串,用来设置或获取位于对象起始和结束标签内的HTML.(获取HTM ...

  5. select2获取选中的val和text

    用自己起的id就可以 获取val:$("#id").val() 获取text:$("#id").select2("data")[0].tex ...

  6. jQuery中的html,val,text区别

    在项目开发中,写jQuery代码有时候会搞混淆一下东西,现在写一下demo来列出jQuery的.html(),.text(),.val()的区别. 1. html()取得第一个匹配元素的内容,简单来说 ...

  7. 常用元素的属性/方法 attr / val / html /text

    常用元素的属性/方法 得到一个元素的高度, $("#myid").height() 得到一个元素的位置, $("#myid").offset() 返回的是一个o ...

  8. 获取select 的 val 和 text [转引]

    (原文地址:http://apps.hi.baidu.com/share/detail/6152780) jQuery获取Select选择的Text和Value:语法解释:1. $("#se ...

  9. val();html();.text()区别

    对于innerHTML 属性,几乎所有的元素都有innerHTML属性,它是一个字符串,用来设置或获取位于对象起始和结束标签内的HTML.(获取HTML当前标签的起始和结束里面的内容) 对于inner ...

随机推荐

  1. golang consistent hash 菜鸟分析

    一直找集群的算法,刚好golang上面有一个适合.下面作为菜鸟来分析一下 // Copyright (C) 2012 Numerotron Inc. // Use of this source cod ...

  2. [Leetcode Week4]H-Index

    H-Index题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/h-index/description/ Description Given an arr ...

  3. PoI导出列表优化

    针对写了头信息之后,使用for循环遍历会导致数据丢失问题的优化,使用迭代器替代for循环,具体如下: public static boolean ExportDeptLeaderFileToLocal ...

  4. PYTHON设计模式学习(3):Singleton pattern

    参考了其他的博客:http://ghostfromheaven.iteye.com/blog/1562618 #-*- encoding=utf-8 -*- print '-------------- ...

  5. Centos 下,配置 Apache + Python + Django + postgresSQL 开发环境

    用 Python 搭建一个 Web 服务器 文章结构 一.安装  Apache.Python.django 二.安装 mod_wsgi,Apache 为 Python 提供的 wsgi 模块  三.将 ...

  6. 【hdoj_1257】最小拦截系统

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1257 可以这样理解题意:给出一组数字,给它们划分组数,划分的依据是,每一组的元素必须是单调递减的顺序,只有 ...

  7. 在WINDOWS2008 Server 中创建NFS服务器,使用LINUX的MOUNT命令去加载网络盘

    1.在WINDOWS服务器中创建NFS SERVER 首先,打开服务管理器,选择添加角色:     选中文件服务,下一步:     出现一个提示,不管它,继续下一步:     在接下来的页面中选中“网 ...

  8. Python 进阶 之 @property

    @property是一个装饰器,由Python原生库所支持,无需import @property 的作用是将函数变成属性,一般作用于类内的成员函数. 先贴个代码来描述一下@poperty存在的意义: ...

  9. IOC(控制反转)的理解

    1.IOC的理论背景 我们知道在面向对象设计的软件系统中,它的底层都是由N个对象构成的,各个对象之间通过相互合作,最终实现系统地业务逻辑[1]. 图1 软件系统中耦合的对象 如果我们打开机械式手表的后 ...

  10. c#实现Form窗体始终在桌面最前端显示

    方法一 //调用API [System.Runtime.InteropServices.DllImport("user32", CharSet = System.Runtime.I ...