jQuery/Href参数

KS1*_*KS1 1 javascript ajax jquery

我正在寻找一种方法,我可以使用一个国家列表...所以当你点击一个链接时,国家代码参数会被传递给qjuery,这将返回一个城市列表.

我已经能够使用下拉列表完成所有这些操作,但是想将其更改为a.href链接.

像下面这样的东西......

$('#country').click(function(event) {  
// get the countryCode value here
var $country=$("a#country").val();
...
Run Code Online (Sandbox Code Playgroud)

这些需要通过countryCode

<a href="#" id="country">Australia</a>
<a href="#" id="country">United Kingdom</a>
<a href="#" id="country">NewZealand</a>
Run Code Online (Sandbox Code Playgroud)

Mar*_*mro 5

在html5中最好使用自定义属性:

<a href="#" class="country" data-code="au">Australia</a>
<a href="#" class="country" data-code="uk">United Kingdom</a>
<a href="#" class="country" data-code="nz">NewZealand</a>
Run Code Online (Sandbox Code Playgroud)

在JS中:

$('.country').click(function(event) {  
    var $country = $(this).data('code');
}
Run Code Online (Sandbox Code Playgroud)

  • 你不能拥有ID国家的所有人. (2认同)