javascript - jquery 如何向input value里追加值
本文介绍了javascript - jquery 如何向input value里追加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
</head>
<style type="text/css">
.box{width: 600px;height: 300px;border: 1px solid #ccc;margin: 0 auto}
.func span{margin-right: 10px;cursor: pointer;}
</style>
<body>
<div class="box">
<input type="text" name="" value="">
</div>
<div class="func">
<span>补水,</span><span>保湿,</span><span>去皱,</span><span>美白,</span>
</div>
</body>
<script type="text/javascript">
$(".func span").click(function(){
h=$(this).html();
$(".box input").attr("value").append(h);
});
</script>
</html>
我这里写的是错的 我是想实现 点一下span 然后往input value里添加一个值
解决方案
$(".box input").val($(".box input").val() + h)
这篇关于javascript - jquery 如何向input value里追加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文