0
我在爲我的項目使用genderAPI和jQuery
。
我想獲得#name
的性別結果,但好像我的代碼根本不認識它(沒有alert
正在跳出)。有人會建議你爲什麼好嗎?jQuery:從性別獲得結果API
他們提供的jQuery plugin
例子如下:
$('input#firstname').genderApi({key: genderApiClientKey}).on('gender-found', function(e, result) {
if (result.accuracy >= 60) {
alert('Gender found: ' + result.gender);
}
});
下面是我的嘗試,你會發現完整的代碼here:
HTML:
<head>
<script type="text/javascript" src="https://gender-api.com/js/jquery/gender.js"></script>
</head>
<body>
<section id="fetch">
<input type="text" placeholder="Please enter your name here" id="term" />
<button type="button" id="search">ENTER</button>
</section>
<div id="name">
<div id="nameBox">
</div>
<div id="nameText">
</div>
</div>
</body>
的jQuery:
var apiUrl = "https://sheetsu.com/apis/f924526c"; // this is another API I created on Google Spreadsheet
$.getJSON(apiUrl, function (json) {
console.log(JSON.stringify(json));
var item = json.result.find(function (e) {
return e.name == content;
}) || json.result[0];
console.log("PRINT ID: " + item.id);
var name = item.name || content;
var $nameText = $("#nameText"),
str = name;
html = $.parseHTML(str),
nodeNames = [];
$nameText.append(html);
console.log("Name: " + name);
// genderAPI here to get gender result
$('name').genderApi({
key: "oyxLJkutVSYXWNVzGP"
}).on('gender-found', function (e, result) {
if (result.accuracy >= 60) {
alert('Gender found: ' + result.gender);
}
});
});
感謝很多:)))× –