.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. 解决cursor未关闭造成的死锁

    参考:https://blog.csdn.net/zc474235918/article/details/72731363/ https://blog.csdn.net/zmx729618/artic ...

  2. System and method for parallel execution of memory transactions using multiple memory models, including SSO, TSO, PSO and RMO

    A data processor supports the use of multiple memory models by computer programs. At a device extern ...

  3. 在shell脚本中添加暂停,按任意键继续

    分析一个复杂脚本的时候,有时候需要加点暂停,分段来看,比较清晰 于是参考了一些实现,目前自己用的是这样子的 #add for debug by zqb function get_char() { SA ...

  4. MSP432P401R时钟入门

    拿到msp432的板子差不多一年了,刚刚进行了开机点亮LED工程:         首先是msp432的时钟模块(CS),个人理解msp432最特色的功能应该是超低功耗和高性能的组合.432系列的时钟 ...

  5. 安装cuda8.0时出现错误:Missing recommended library: libGLU.so Missing recommended library: libGL.so

    安装cuda8.0时出现错误: Missing recommended library: libGLU.soMissing recommended library: libGL.so Installi ...

  6. WPF第三方控件盘点

    WPF统一的编程模型.语言和框架,实现了界面设计人员和开发人员工作可以分离的境界,鉴于WPF强大的优势,且一直是开发者关注的地方,下面和大家分享基于WPF项目开发需要用到的第三方控件,包括业界最受好评 ...

  7. 中小型mysql数据库的备份与恢复

    #转载请联系 备份到桌面 cd /home/chichung/Desktop # 切换到桌面 mysqldump -u root -p db_jingdong>jd.sql # 重定向写入 jd ...

  8. jQuery 入门笔记1

    jQuery是一个兼容多浏览器的javascript框架,核心理念是write less,do more(写得更少,做得更多). 1:jQuery使用 <script type="te ...

  9. MyBatis3-实现多表关联数据的查询

    前提: 1.新建Article表和增加模拟数据,脚本如下: Drop TABLE IF EXISTS `article`; Create TABLE `article` ( `id` ) NOT NU ...

  10. Selenium2+python自动化52-unittest执行顺序【转载】

    前言 很多初学者在使用unittest框架时候,不清楚用例的执行顺序到底是怎样的.对测试类里面的类和方法分不清楚,不知道什么时候执行,什么时候不执行. 本篇通过最简单案例详细讲解unittest执行顺 ...