我正在寻找一种方法,我可以使用...获得国家/地区列表,因此当您单击链接时,国家/地区代码参数将传递给 qjuery,后者将返回城市列表。
我已经能够使用下拉菜单完成所有这些操作,但我想将其更改为 a.href 链接。
类似下面的内容......
$('#country').click(function(event) {
// get the countryCode value here
var $country=$("a#country").val();
...
这些需要通过countryCode
<a href="#" id="country">Australia</a>
<a href="#" id="country">United Kingdom</a>
<a href="#" id="country">NewZealand</a>
最佳答案
在 html5 中最好使用 custom attribute :
<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>
在 JS 中:
$('.country').click(function(event) {
var $country = $(this).data('code');
}
关于javascript - jQuery/Href 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20056065/