jQuery 中的 val( )方法函数

首页 / jQuery入门教程 / jQuery 中的 val( )方法函数

val()方法获取第一个匹配元素的输入值。

val( ) - 语法

selector.val( ) 

val( ) - 示例

以下示例将在第二段中设置第一个输入框的HTML内容-

链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/attr-val.html

来源:LearnFk无涯教程网

<html>
   <head>
      <title>The Selecter Example</title>
      <script type="text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
   
      <script type="text/javascript" language="javascript">
         $(document).ready(function() {
            var content=$("input").val();
            $("p#pid2").text(content);
         });
      </script>
      
      <style>
         .red { color:red; }
         .green { color:green; }
      </style>
   </head>
   
   <body>
      <input type="text" value="First Input Box"/>
      <input type="text" value="Second Input Box"/>
      <p class="green" id="pid1">This is <i>first paragraph</i>.</p>
      <p class="red" id="pid2">This is second paragraph.</p>
   </body>
</html>

这将产生以下输出-

无涯教程网

 

This is first paragraph.

First Input Box

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

深入剖析Kubernetes -〔张磊〕

架构实战案例解析 -〔王庆友〕

Java业务开发常见错误100例 -〔朱晔〕

Redis核心技术与实战 -〔蒋德钧〕

Spark核心原理与实战 -〔王磊〕

A/B测试从0到1 -〔张博伟〕

商业思维案例笔记 -〔曹雄峰〕

AI绘画核心技术与实战 -〔南柯〕

LangChain 实战课 -〔黄佳〕

好记忆不如烂笔头。留下您的足迹吧 :)