这是一个工作代码:
const AppRouter = () => (
<BrowserRouter>
<div>
<Header />
<Switch>
<Route path="/" component={DashboardPage} exact={true} />
<Route path="/:id" component={ViewerPage} /> // <-- Exclude Header component from this page
<Route path="/create" component={CreatePage} />
<Route path="/edit/:id" component={EditPage} />
<Route path="/help" component={HelpPage} />
<Route component={NotFoundPage} />
</Switch>
</div>
</BrowserRouter>
);
export default AppRouter;
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚如何从 ViewerPage 组件页面中排除 Header 组件。有没有办法做到这一点?
我试图找出如何根据使用javascript在另一个输入字段中输入的内容自动填充输入值.这是我的代码:
<script>
add = document.getElementById('address').value;
city = document.getElementById('city').value;
state = document.getElementById('state').value;
zip = document.getElementById('zip').value;
compAdd = add+" "+city+" "+state+" "+zip;
function showAdd(){
document.getElementById('shipadd1').value=compAdd;
document.getElementById('add1').innerHTML=compAdd;
}
</script>
<form action="" onchange="showAdd();">
Home Address: <input id="address" name="address" type="text" /><br/>
Apt or Suite Number: <input id="suite" name="suite" type="text" /><br/>
City/Town: <input id="city" name="city" type="text" /><br/>
State:<select id="state" name="state" value="">...</select><br/>
Zip:<input id="zip" name="zip" type="text" value=""/><br/>
<p> Select Shipping Address Below: </p>
<input type="checkbox" id="shipping-address-1" name="address1" value=""><span id="shiadd1">(Print auto-populated shipping address here...)</span>
<input type="checkbox" id="shipping-address-2" name="address2" …Run Code Online (Sandbox Code Playgroud) 我有隐藏输入标签的变量名称和值,我想在单击提交按钮时将其附加到表单中。我该如何编码?
这是我的代码:
<script type="text/javascript">
hname="reference";
hvalue="1";
function insertInput(){
document.write( "<input type='hidden' name='" + hname + " ' value=' " + hvalue + " '/><br/>");
}
</script>
<form id="form1">
<p><label>Username:</label> <input type="text" name="username" size="10"/></p>
<p><label>Password:</label> <input type="password" name="password" size="10"/></p>
<p id="hidden"><!-- Insert Hidden input tag here --></p>
<button type="submit' onClick="insertInput();">Log In</button>
</form>
Run Code Online (Sandbox Code Playgroud)
我似乎无法让它工作。
我一直试图让countDown()函数在render()函数中自动运行,但似乎无法搞清楚.这是代码:
import React from 'react';
import ReactDOM from 'react-dom';
class Counter extends React.Component {
constructor(props) {
super(props);
this.countDown = this.countDown.bind(this);
this.state = {
count: 5,
message: ''
}
}
countDown() {
setInterval(() => {
if (this.state.count <= 0) {
clearInterval(this);
this.setState(() => {
return {message: "Click here to skip this ad"}
})
} else {
this.setState((prevState) => {
return {count: prevState.count - 1}
})
}
}, 1000)
}
render() {
return (
<div>
<h1 onLoad={this.countDown}>
{this.state.message ? this.state.message : this.state.count} …Run Code Online (Sandbox Code Playgroud) 如何使用JavaScript在我想要的每个页面的内容部分中插入第二个通用(无添加ID或类)"p"节点/标记之后出现的自定义"div"元素?
例如:
<div id="main-content">
<p>1st paragraph content.....</p>
<p>2nd paragraph content.....</p>
<p>3rd paragraph content.....</p>
</div>
Run Code Online (Sandbox Code Playgroud)
输出:
<div id="main-content">
<p>1st paragraph content.....</p>
<p>2nd paragraph content.....</p>
<div id="custom-div">Content here...</div>
<p>3rd paragraph content.....</p>
</div>
Run Code Online (Sandbox Code Playgroud) javascript ×5
forms ×2
input ×2
reactjs ×2
dom ×1
function ×1
html ×1
jquery ×1
react-router ×1