我正在尝试使用下面的代码将按钮添加到我的页面正文中,按钮出现,但没有显示任何属性,它是一个默认按钮,不增加字体大小,没有文本显示,也没有颜色.
function createKeyboard()
{
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(var i=0; i<str.length; i++)
{
var nextChar = str.charAt(i);
var btn = document.createElement("BUTTON");
btn.setAttribute("id","btn"+nextChar);
btn.setAttribute("innerHtml",nextChar);
btn.setAttribute("value",nextChar);
btn.setAttribute("text",nextChar);
btn.setAttribute("font-size","14px");
btn.setAttribute("background-color","#4CAF50");
document.body.appendChild(btn);
}
};Run Code Online (Sandbox Code Playgroud)
使用控制台查看按钮时,我可以看到属性,如下所示:
<button id="btnA" innerhtml="A" value="A" text="A" font-size="14px" background-color="#4CAF50"></button>Run Code Online (Sandbox Code Playgroud)
不确定我在哪里出错了,有什么想法吗?
-谢谢
我将在序言中说我对Angular2很新.我需要找到一种方法来打开一个登录失败的警报Modal,代码在下面评论"//登录失败",我找到的所有例子都依赖于按钮点击,有没有办法根据布尔状态执行此操作值?
import { Component } from '@angular/core';
import { UsersService } from '../users.service';
import { Router } from '@angular/router';
import { ModalModule } from 'ngx-modal';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent {
constructor(private usersService: UsersService, private router: Router) {}
user: string;
pass: string;
liwr: boolean = false;
loginPressed(username, password){
console.log(username + " " + password);
this.usersService.loginAttempt(username, password).subscribe(response => {
console.log(response[1]);
//admin login
if (response[0].status === 'success' && response[1].userInfo.privilegeStatus === 'admin'){
this.router.navigateByUrl('/posts');
this.usersService.authStatus = response[1].isAuth;
this.usersService.userSessionObj …Run Code Online (Sandbox Code Playgroud)