})
.then(response => response.json())
.then(myJson => this.setState({firmsList:myJson}))
}
},300)
}
);
}
//input输⼊框点击事件
inputClick = () =>{
let adepsp = ElementById("adepsp");
let adepmatch = ElementById("adepmatch");
adepsp.style.border = "0.1rem solid #32CD32";
adepmatch.style.display = "block";
}
//匹配列⿏标点击事件
onClick = event =>{
//点击<li>,将<li>内容赋值给input;
this.setState({searchValue:event.target.innerHTML});
let adepmatch = ElementById("adepmatch");
event.target.style.display = "none";
adepmatch.style.display="none";
}
//渲染节点
input绑定onblur事件render(){
return (
<React.Fragment>
<div>
<span className="adepstyle" id="adepsp">
<span className="adeplable">
起飞机场
</span>
<span className="adepspan">
<input className="adepinput" id="adep"
type="text" name="adep" value={this.state.searchValue} onClick={this.inputClick}
// onBlur={Blur}
onChange={this.handleChange} />
</span>
</span>
</div>
<div className="match" id="adepmatch" >
<ul>
{this.state.firmsList.map((adep) =>
<li key={adep.id} onClick={Click}>
{adep.wexp + adep.cfullname}
</li>
)}
</ul>
</div>
</React.Fragment>
);
}
}
export default App;
index.css⽂件如下:
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
.adepstyle{
padding: 0.1rem;
width: 20rem;
border: 0.1rem solid rgba(105,105,105,0.5);
border-radius: 0.3rem;
}
.adeplable{
border-right: 0.05rem solid rgba(105,105,105,0.5);
padding: 0 0.5rem;
}
.adepinput{
font-size: 1rem;
height: 1rem;
border: 0;
outline: none;
}
.adepspan{
margin: 0 0.5rem;
}
li{
list-style: none;
}
div{
padding: 0rem;
color: rgb(139,137,137);
margin: 3rem 1rem 0 3rem;
}
div.match{
width: 13.5rem;
position: absolute;
top: 1.44rem;
left: 8.2rem;
background-color: rgb(255,255,255);
border: 0.0625rem solid #32CD32;
display: none;
}
ul,li{
list-style: none;
padding: 0;
margin: 0 0 0 0.4rem;
}
li:hover{
color: #000000;
}
index.html⽂件如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/
>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See le/web/fundamentals/web-app-manifest/ -->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
<script>
let adepsp = ElementById("adepsp");
let adepmatch = ElementById("adepmatch");
adepsp.style.border = "0.1rem solid rgba(105,105,105,0.5)";
adepmatch.style.display = "none";
}
</script>
</body>
</html>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论