我想调用这个Javascript函数。当我点击我的按钮时,没有任何加载。我为我的按钮设置了一个ID。使用onclick我加载函数onLinkedInLoad。但是,这不是我应该打电话来激活脚本的功能吗?任何人都可以看到我在这里做错了吗?调用JS函数onClick
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<button id="btn">Try Me</button>
<script type="text/javascript">
document.getElementById("btn").onclick = onLinkedInLoad;
</script>
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: myKey
authorize: true
onLoad: onLinkedInLoad
</script>
<script type="text/javascript">
// Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
IN.Event.on(IN, "auth", shareContent);
}
// Handle the successful return from the API call
function onSuccess(data) {
console.log(data);
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
}
// Use the API call wrapper to share content on LinkedIn
function shareContent() {
// Build the JSON payload containing the content to be shared
var payload = {
"comment": "Check out developer.linkedin.com! http://linkd.in/1FC2PyG",
"visibility": {
"code": "anyone"
}
};
IN.API.Raw("/people/~/shares?format=json")
.method("POST")
.body(JSON.stringify(payload))
.result(onSuccess)
.error(onError);
}
</script>
</body>
</html>
更新: 我得到这个在我的控制台:
18 Uncaught ReferenceError: onLinkedInLoad is not defined
www.linkedin.com/uas/js/userspace?v=0.0.1191-RC8.56309-1429&apiKey=myKey&authorize=true&onLoad=onLinkedInLoad&secure=1&:
22 Uncaught Error: You must specify a valid JavaScript API Domain as part of this key's configuration.
我的推杆我APIkey中也。我在这里用“myKey”替换了代码。我也尝试过.addEventListener('click', onLinkedInLoad)
,但仍然没有任何反应
你检查了你的控制台是否有错误? –
而不是'.onclick = onLinkedInLoad'尝试'.addEventListener('click',onLinkedInLoad)' – mpallansch
您尝试过吗?试试我 –