我能解决这个问题做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,它是本机脚本 –