87,925
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<title>test</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
<!--
function addstr(){
var $text = $("#test").val() + " " + $(this).text()
$("#test").val($.trim($text));
$(this).attr("style","background-color:#ccc;");
}
function removestr(){
var $text = $(this).text();
var retext = new RegExp($text+" ?" , "g");
$text = $("#test").val().replace(retext,"");
$text = $.trim($text);
$("#test").val($text);
$(this).attr("style","");
}
$(function (){
$("#testlink a").toggle(addstr,removestr);
});
//-->
</script>
</head>
<body>
<input id = "test" type="text" />
<div id = "testlink">
<a href="javascript:;">link1</a>
<a href="javascript:;">link2</a>
<a href="javascript:;">link3</a>
</div>
</body>
</html>
$(function (){
$("#testlink a").click(toggle(addstr,removestr));
});
$(function (){
$("#testlink a").toggle(addstr,removestr);
});
<input id = "test" type="text" />
<div id = "testlink">
<a href="javascript:;">link1</a>
<a href="javascript:;">link2</a>
<a href="javascript:;">link3</a>
</div>
function addstr(){
var $text = $("#test").val() + " " + $(this).text()
$("#test").val($.trim($text));
}
function removestr(){
var $text = $(this).text();
var retext = new RegExp($text+" ?" , "g");
$text = $("#test").val().replace(retext,"");
$text = $.trim($text);
$("#test").val($text);
}
$(function (){
$("#testlink a").click(toggle(addstr,removestr));
});