我不知道我创建的函数中出现了什么问题。我试图创造一个美丽的国家选择。但看起来这个选择器不会选择任何东西。只是开玩笑,所以我的问题是根据我的想法,我的功能应该改变输入字段的值,该字段归类为country_input
点击多个系列的链接。但它看起来不会工作。但你们可以告诉我如何实现我的目标。使用函数为输入添加值
- ::: - HTML代码 - ::: -
<input type="text" class="country_input" />
<br><br>
<a href="#country-select" id="Change-1" onclick="change_country();" >Country-1</a>
<a href="#country-select" id="Change-2" onclick="change_country();" >Country-2</a>
<a href="#country-select" id="Change-3" onclick="change_country();" >Country-3</a>
<a href="#country-select" id="Change-4" onclick="change_country();" >Country-4</a>
<a href="#country-select" id="Change-5" onclick="change_country();" >Country-5</a>
And so on....
- ::: - jQuery代码 - ::: -
jQuery.fn.change_country = function() {
var country_name = $(this).innerHTML;
$('input.country_input').val(country_name);
};
- :: : - CSS代码 - ::: -
body a { text-decoration: none; display: block; width: 50%; color: #555; background: rgb(240, 240, 240); border: 2px solid #000; border-style: none none solid none; font-family: calibri,segoe ui,arial, sans-serif; font-size: 12px; padding: 3px 5px; }
body a:hover { color: #000; background: #fff; }
body input { font-family: calibri,segoe ui,arial, sans-serif; font-size: 12px; padding: 3px 3px; width: 50%; outline: none; }
所以任何人都可以帮我解决这个问题。由于我是创建基于jQuery的函数的新手,所以请帮助我。
我在做错误的函数定义吗? 我错过了什么吗? 我的代码是完全失败的吗?
提前感谢!
感谢哥们!这工作!再次感谢。 – 2011-04-09 17:26:01
@Jack Billy:Np,很高兴提供帮助。我编辑了我的答案,以防您想使用下拉列表进行选择。 – Damb 2011-04-09 17:35:18