自动生成文字和自己填写

<!DOCTYPE html>
<html>
<head lang="zh-cn">
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" name="viewport"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no"/>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<title></title>
</head>
<body>
<p class="more" id="intro">
<span>自我介绍</span>
<span id="mod1" class="on-selected">点我自动生成</span>
<span id="mod2">点我自己填写</span>
</p>
<p class="text">
<textarea name="text" id="text" class="sddf" placeholder="介绍一下自己吧,300字以内"></textarea>
</p>
<script>
function randomIntroduce () {
var introArr = [
{txt: "这是文本一"},
{txt: "这是文本二"},
{txt: "这是文本三"},
{txt: "这是文本四"}
];
var len = introArr.length;
var rst = Math.floor(Math.random()*len);
$("#text").val(introArr[rst].txt)
}
$("#intro span:not(:first-child)").click(function(){
$(this).addClass("on-selected").siblings().removeClass("on-selected")
if($(this).text() == "点我自己填写") {
$("#text").val("");
$("#text").attr({
"placeholder": "自我介绍内容控制在300字以内"
})
} else {
// $("#text").text("");
randomIntroduce();
}

})
</script>
</body>
</html>
posted @ 2017-05-22 09:54  zc_boy  阅读(289)  评论(0编辑  收藏  举报