Best JavaScript code snippet using wpt
index.js
Source:index.js
1import React from 'react'2import { Layout, Row, Col, Card, Carousel, Button } from 'antd';3const { Header, Footer, Content } = Layout;4import './index.css'5import img from '../static/img/bg.jpg'6import {7 login8} from '../axios/api'9import {10 UserSwitchOutlined,11 ArrowRightOutlined,12} from '@ant-design/icons'13const styles = {14 title: {15 backgroundColor: "#19478b",16 fontSize: '25px',17 color: 'white',18 fontWeight: 'bold',19 },20 engTitle: {21 backgroundColor: "#19478b",22 fontSize: '15px',23 color: 'white',24 fontWeight: 'bold',25 marginTop: '-40px'26 },27 contentStyle: {28 width: '100%',29 height: '500px'30 },31 inputStyle: {32 outline: 'none',33 border: "none",34 borderBottom: '1px solid gray',35 width: '100%',36 marginTop: '30px',37 paddingRight: '40px'38 },39 loginBtn: {40 position: 'absolute',41 top: '20px',42 right: '0px'43 }44}45class Login extends React.Component {46 constructor() {47 super()48 this.state = {49 errorFont: '',50 password: '',51 user: ''52 }53 }54 handleLogin = async () => {55 const { user, password } = this.state56 if (user === '' || password === '') {57 this.setState({ errorFont: "è´¦å·æè
å¯ç ä¸è½ä¸ºç©º" })58 return59 }60 try {61 let res = await login({ user, password })62 const { status, token, msg } = res63 if (status === '200') {64 window.localStorage.setItem('token', token)65 this.props.history.push('/home/worldmap')66 } else {67 this.setState({ errorFont: msg })68 }69 } catch (e) {70 console.log(e)71 }72 }73 render() {74 const { errorFont, user, password } = this.state75 return <React.Fragment>76 <Layout className='login-layout' >77 <Header className='login-header'>78 <div style={styles.title}>å®ç§ç«æ
é²æ§å¹³å°</div>79 <div style={styles.engTitle}>Epidemic prevention control platform</div>80 </Header>81 <Content className='login-content'>82 <Row >83 <Col span={18} style={{ height: '500px' }}>84 <Carousel autoplay>85 <div>86 <img src={img} style={styles.contentStyle} alt="" />87 </div>88 <div>89 <img src={img} style={styles.contentStyle} alt="" />90 </div>91 <div>92 <img src={img} style={styles.contentStyle} alt="" />93 </div>94 </Carousel>95 </Col>96 <Col span={6} >97 <Card title={"ç»é"} bordered={false} style={{ height: '100%' }}>98 <div style={{ textAlign: 'center' }}>99 <UserSwitchOutlined style={{ fontSize: '40px' }} />100 </div>101 <div>102 <input type="text" style={styles.inputStyle} placeholder='è´¦å·' value={user} onChange={(e) => {103 this.setState({104 user: e.target.value105 })106 }} />107 </div>108 <div style={{ position: 'relative' }}>109 <input type="password" style={styles.inputStyle} placeholder='å¯ç ' value={password}110 onChange={(e) => {111 this.setState({112 password: e.target.value113 })114 }}115 onKeyDown={(e) => {116 if (e && e.key == 'Enter') {117 this.handleLogin()118 }119 }}120 />121 <Button type="circle" style={styles.loginBtn} icon={<ArrowRightOutlined />} onClick={() => { this.handleLogin() }} />122 </div>123 <div style={{ fontSize: "13px", color: 'red', marginTop: "10px" }}>{errorFont ? errorFont : null}</div>124 </Card>125 </Col>126 </Row>127 </Content>128 <Footer className='login-footer'>129 <div style={{ textAlign: 'center' }}>Copyright© å®å¾½ç§æå¦é¢ çICPå¤12009839å· English</div>130 </Footer>131 </Layout>132 </React.Fragment>133 }134}...
login.js
Source:login.js
1$('.form').Validform({2 tiptype: function(msg, o, cssctl) {3 if (!o.obj.is("form")) {4 var objtip = o.obj.parents('.input_box').siblings('.error_tip ').children(".errorRedIcon");5 var red = o.obj.siblings('.error_Icon');6 var redline = o.obj.siblings('.errorRedLine');7 var text = o.obj.parents('.input_box').siblings('.error_tip ').children(".errorFont ");8 9 if (o.type != 2) {10 objtip.css('display', 'block');11 red.css('display', 'block');12 redline.css('display', 'block');13 text.css('display','block');14 text.text(msg);15 } else {16 text.text('');17 objtip.css('display', 'none');18 red.css('display', 'none');19 redline.css('display', 'none');20 text.css('display','none');21 }22 console.log(o.obj.is("form"))23 } else {24 }25 },26});27$('.login').click(function () {28 var telText = $('#tel').val();29 var passText=$('#pass1').val();30 if(telText==$.cookie('username')&&passText==$.cookie('userpass')){31 document.cookie="isLogin="+true;32 window.location.href="index.html";33 }else{34 var errorFont=document.querySelector('.errorFont');35 console.log(errorFont);36 $('.errorFont').text('è´¦å·æå¯ç é误!');37 $('.errorFont').css('display','block');38 $('.errorRedIcon').css('display','block')39 }...
beauty.js
Source:beauty.js
1//selector2const emailInput = document.getElementById('email');3const emailSubmit = document.querySelector('.submit-btn')4const errorIcon = document.querySelector('.error-icon');5const errorFont = document.querySelector('.error');6//function7const submit = ()=>{8let emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;9 if(emailRegex.test(emailInput.value) ){10 errorIcon.classList.remove('showOn');11 errorFont.classList.remove('showOn');12 } else{13 errorIcon.classList.add('showOn');14 errorFont.classList.add('showOn');15 }16}17//eventListener18emailSubmit.addEventListener('click',submit)19//eventListener check input20emailInput.addEventListener('input', ()=>{21 if(emailInput.value == ''){22 errorIcon.classList.remove('showOn');23 errorFont.classList.remove('showOn');24 }...
Using AI Code Generation
1wpt.ErrorFont('Arial', 10, 1);2wpt.ErrorColor(255, 0, 0);3wpt.ErrorColor(255, 0, 0);4wpt.ErrorColor(255, 0, 0);5wpt.ErrorColor(255, 0, 0);6wpt.ErrorColor(255, 0, 0);7wpt.ErrorColor(255, 0, 0);8wpt.ErrorColor(255, 0, 0);9wpt.ErrorColor(255, 0, 0);10wpt.ErrorColor(255, 0, 0);11wpt.ErrorColor(255, 0, 0);12wpt.ErrorColor(255, 0, 0);
Using AI Code Generation
1var page = require('webpage').create();2 page.evaluate(function() {3 var textbox = document.getElementById('textbox');4 textbox.value = 'Hello World';5 textbox.style.fontFamily = 'Arial';6 textbox.style.fontSize = '20pt';7 textbox.style.color = 'green';8 textbox.style.fontWeight = 'bold';9 textbox.style.fontStyle = 'italic';10 textbox.style.textDecoration = 'underline';11 textbox.style.textAlign = 'center';12 textbox.style.verticalAlign = 'middle';13 textbox.style.width = '300px';14 textbox.style.height = '50px';15 textbox.style.backgroundColor = 'yellow';16 textbox.style.borderColor = 'blue';17 textbox.style.borderWidth = '2px';18 textbox.style.borderStyle = 'solid';19 textbox.style.borderRadius = '10px';20 textbox.style.padding = '2px';21 textbox.style.margin = '10px';22 textbox.style.position = 'relative';23 textbox.style.left = '50px';24 textbox.style.top = '50px';25 textbox.style.zIndex = '10';26 textbox.style.outline = 'none';27 textbox.style.boxShadow = '5px 5px 5px #888888';28 textbox.style.webkitBoxShadow = '5px 5px 5px #888888';29 textbox.style.mozBoxShadow = '5px 5px 5px #888888';30 textbox.style.opacity = '0.5';31 textbox.style.filter = 'alpha(opacity=50)';32 textbox.style.transform = 'rotate(45deg)';33 textbox.style.webkitTransform = 'rotate(45deg)';34 textbox.style.mozTransform = 'rotate(45deg)';35 textbox.style.msTransform = 'rotate(45deg)';36 textbox.style.oTransform = 'rotate(45deg)';37 textbox.style.transformOrigin = '50% 50%';38 textbox.style.webkitTransformOrigin = '50% 50%';39 textbox.style.mozTransformOrigin = '50% 50%';40 textbox.style.msTransformOrigin = '50% 50%';41 textbox.style.oTransformOrigin = '50% 50%';42 textbox.style.transition = 'all 2s ease';43 textbox.style.webkitTransition = 'all 2s ease';44 textbox.style.mozTransition = 'all 2s ease';
Using AI Code Generation
1var canvas = new fabric.Canvas('c');2var textbox = new fabric.IText('Hello World!', {3});4canvas.add(textbox);5textbox.ErrorFont("Non-existent font");6textbox.render(canvas.getContext("2d"));
Using AI Code Generation
1function test() {2 var txt = new wptextbox();3 var font = new wpfont();4 var font2 = new wpfont();5 txt.Font = font;6 txt.ErrorFont = font2;7 var font3 = txt.ErrorFont;8 if (font3 != font2) {9 throw "ErrorFont method failed";10 }11}12function test() {13 var txt = new wptextbox();14 txt.ErrorForeColor = "red";15 var color = txt.ErrorForeColor;16 if (color != "red") {17 throw "ErrorForeColor method failed";18 }19}20function test() {21 var txt = new wptextbox();22 txt.ErrorText = "error";23 var text = txt.ErrorText;24 if (text != "error") {25 throw "ErrorText method failed";26 }27}28function test() {29 var txt = new wptextbox();30 txt.ErrorVisible = true;31 var visible = txt.ErrorVisible;32 if (visible != true) {33 throw "ErrorVisible method failed";34 }35}36function test() {37 var txt = new wptextbox();38 txt.ForeColor = "red";39 var color = txt.ForeColor;40 if (color != "red") {41 throw "ForeColor method failed";42 }43}44function test() {45 var txt = new wptextbox();46 txt.Height = 100;47 var height = txt.Height;48 if (height != 100) {49 throw "Height method failed";50 }51}52function test() {53 var txt = new wptextbox();54 txt.IsPassword = true;55 var isPassword = txt.IsPassword;56 if (isPassword != true) {57 throw "IsPassword method failed";58 }59}
Using AI Code Generation
1const wptools = require('wptools');2const wiki = wptools.page('Sachin Tendulkar');3wiki.get().then(function (page) {4 if (page.exists()) {5 page.fonts().then(function (fonts) {6 console.log(fonts);7 });8 }9});10{11 {12 },13 {14 },15 {16 },17 {18 },19 {20 },21 {22 },23 {24 },25 {26 },27 {28 },29 {30 },31 {32 },33 {34 },35 {36 },37 {38 },39 {40 }41}42const wptools = require('wptools');43const wiki = wptools.page('Sachin Tendulkar');44wiki.get().then(function (page) {45 if (page.exists()) {46 page.wordCount().then(function (wordCount) {47 console.log(wordCount);48 });49 }50});51{52}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!