我要实现的效果如下,就是点击链接显示点击对象的文本<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title> new document </title>
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
(function($){
$.fn.myTest = function(options)
{
var defaults = {
d : "text"
}
var config = $.extend(defaults,options); this.click(function()
{
alert("default : " + $(this).text());
return false;
})
}
})(jQuery);$(function()
{
$(".test").myTest();
})
</script>
</head>
<body>
<a href="#" class="test">xxx</a> - <a href="#" class="test">yyy</a>
</body>
</html>我想改成参数调用形式,在jquery插件引入一个参数,然后调用,但是显然下面的代码运行不了,如何改下下面的代码实现上面的效果<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title> new document </title>
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
(function($){
$.fn.myTest = function(options)
{
var defaults = {
d : "text"
}
var config = $.extend(defaults,options); this.click(function()
{
alert("default : " + config.d);
return false;
})
}
})(jQuery);$(function()
{
$(".test").myTest({d:$(this).text()});
})
</script>
</head>
<body>
<a href="#" class="test">xxx</a> - <a href="#" class="test">yyy</a>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title> new document </title>
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
(function($){
$.fn.myTest = function(options)
{
var defaults = {
d : "text"
}
var config = $.extend(defaults,options); this.click(function()
{
alert("default : " + $(this).text());
return false;
})
}
})(jQuery);$(function()
{
$(".test").myTest();
})
</script>
</head>
<body>
<a href="#" class="test">xxx</a> - <a href="#" class="test">yyy</a>
</body>
</html>我想改成参数调用形式,在jquery插件引入一个参数,然后调用,但是显然下面的代码运行不了,如何改下下面的代码实现上面的效果<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title> new document </title>
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
(function($){
$.fn.myTest = function(options)
{
var defaults = {
d : "text"
}
var config = $.extend(defaults,options); this.click(function()
{
alert("default : " + config.d);
return false;
})
}
})(jQuery);$(function()
{
$(".test").myTest({d:$(this).text()});
})
</script>
</head>
<body>
<a href="#" class="test">xxx</a> - <a href="#" class="test">yyy</a>
</body>
</html>
解决方案 »
- 在DIV中和style中分别定义WIDTH属性有什么区别
- prototype.js 中AJAX不支持#,?等特殊字符如何解决
- window.alert(), window.confirm(),window.prompt()的区别?
- 耽误各位老师几分钟看一下!
- 如何将Text设置成为不可编辑?
- 如何用代码调用onchange等事件??? 好急!!!
- 很急,请大家帮忙:一个关于下拉框获取焦点的问题???
- 爽啊,请大虾解释一下namespace这个东西。顺便现一下丑。
- js解析protobuf
- 初学MV*框架 , 视图复用的提问。高手进!
- 关于回车触发按钮的单击事件
- JS如何操作这种JSON数据啊?这种比较特别的。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title> new document </title>
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
(function($){
$.fn.myTest = function(options)
{
var defaults = {
d : "text"
}
var config = $.extend(defaults,options);
this.click(function()
{
alert("default : " + config.d);
return false;
})
}
})(jQuery);$(function()
{
$(".test").each(function(){
$(this).myTest({d:$(this).text()})
});
})
</script>
</head>
<body>
<a href="#" class="test">xxx</a> - <a href="#" class="test">yyy</a>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title> new document </title>
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
(function($){
$.fn.myTest = function(options)
{
var defaults = {
d : "text"
}
var config = $.extend(defaults,options); this.click(function()
{
alert("default : " + config.d);
$(this).text("hhhh");
return false;
})
}
})(jQuery);$(function()
{
$(".test").each(function()
{
$(this).myTest({d:$(this).text()});
});
})
</script>
</head>
<body>
<a href="#" class="test">xxx</a> - <a href="#" class="test">yyy</a>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title> new document </title>
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
(function($){
$.fn.myTest = function(options)
{
var defaults = {
d : "text"
}
var config = $.extend(defaults,options); this.click(function()
{
alert("default : " + config.d);
alert("now : " + $(this).text());
$(this).text("hhhh");
return false;
})
}
})(jQuery);$(function()
{
$(".test").each(function()
{
$(this).myTest({d:$(this).text()});
});
})
</script>
</head>
<body>
<a href="#" class="test">xxx</a> - <a href="#" class="test">yyy</a>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title> new document </title>
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
(function($){
$.fn.myTest = function(options)
{
var defaults = {
d : "text"
}
var config = $.extend(defaults,options); this.click(function()
{
$(this).text(parseInt(Math.random()*100));
alert("default : " + config.d);
return false;
})
}
})(jQuery);$(function()
{
$(".test").each(function()
{
$(this).myTest({d:$(this).text()});
});
})
</script>
</head>
<body>
<a href="#" class="test">50</a> - <a href="#" class="test">40</a>
</body>
</html>