如何在页面加载时将player-id附加到输入字段?
<input type="text" id="player-id" readonly />
<a id="get_onesignal_token" class="btn btn-primary" onClick="getOneSignalToken()">Get OneSignal player id</a>
<script type="text/javascript">
function getOneSignalToken() {
//alert("RegisterId:" + android.getOneSignalRegisteredId());
$('#player-id').val($('#player-id').val() + android.getOneSignalRegisteredId());
};
</script>
答案 0 :(得分:0)
你应该在onLoad文件中调用你的方法,就像我在body中所做的那样
<body onload="getOneSignalToken()">
<input type="text" id="player-id" readonly />
<a id="get_onesignal_token" class="btn btn-primary" onClick="getOneSignalToken()">Get OneSignal player id</a>
<script type="text/javascript">
function getOneSignalToken() {
//alert("RegisterId:" + android.getOneSignalRegisteredId());
$('#player-id').val($('#player-id').val() + android.getOneSignalRegisteredId());
};
</script>
</body>
如果您还有任何疑问,请告诉我
答案 1 :(得分:0)
$(function getOneSignalToken() {
$('#player-id').val($('#player-id').val() + android.getOneSignalRegisteredId());
})
这很有用。感谢。