<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script src="js/JQ3.3.1.js"></script> <script type="text/javascript"> function fun(){ var msgValue = $(msg).val();//val()函数用以获得内容 console.log("输入的内容是:"+msgValue) } function fun2(){ var msgValue = $(msg).val("一键生成内容");//val()函数还有设置内容的功能 } </script> </head> <body> 输入消息:<input type="text" name="msg" id="msg" /> <input type="button" value="输出内容" onclick="fun()"/> <input type="button" value="设置内容" onclick="fun2()" /> </body> </html>