HTML代码:
$("#theme").val("要修改的值,可以写变量上去,可以用+号连接变量");
<div id="text"> <button id="life" value="生活" >生活</button> <input type="text" id="theme"> </div>
为button设置单击事件:
$("#life").click(function(){ //获取value值 var theme=document.getElementById("theme").value; var life=document.getElementById("life").value; $("#theme").val(theme+life); });关键在于
$("#theme").val("要修改的值,可以写变量上去,可以用+号连接变量");