我能解決這個問題做Android或iOS應用其瀏覽器的事通過將'加載的'屬性添加到「Page」,然後創建一個具有加載屬性的相同名稱的方法,該方法將具有頁面的上下文。以下是代碼。
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded">
<!--
Stack layout for ordering the HTML element at the login page
-->
<StackLayout class="p-20" orientation="vertical">
<!--Fields for getting the username and password for input-->
<TextField hint="UserName" id="usernameID" style="margin-top:5%"/>
<TextField hint="Password" id="passwordID" autocorrect="false" secure="true" style="margin-top:3%"/>
<!--Login button here-->
<Button text="login" tap="onLogin" id="logInButton" class="btn btn-primary btn-active" style="margin-top:5%"/>
</StackLayout>
這裏那張打字稿
import { EventData } from 'data/observable';
import { Page } from 'ui/page';
import { TextField } from 'ui/text-field';
import { Button } from 'ui/button';
let pageLoaded = (args : EventData) =>{
let page = <Page> args.object;
let textValue = <TextField>page.getViewById('usernameID');
let logInButton= <Button>page.getViewById('signUpButton');
logInButton.on('tap',(args:EventData)=>{
console.log('textValue :: '+textValue.text);
});
}
export {pageLoaded}
感謝您的幫助傢伙...乾杯:)
您使用的角度? – saperlipopette
你沒有使用'document.getElementById'。您正在使用'document.getElementsByName'這是一個不同的函數並返回一個NodeList。順便說一句,'TextField'不是一個有效的HTML元素,所以我不確定它會在任何情況下工作。 –
沒有@saperlipopette,它是本機腳本 –