好吧,我觉得这应该很简单;所以要么我完全错过了这里和我读过的其他网站上的问题的重点,要么没有在相同的上下文中被问到......
我有一个非常简单的表单元素(如下)
<form>
<input type="text" id="searchTerm" />
<input type="submit" value="Submit" id="submitButton" />
</form>
Run Code Online (Sandbox Code Playgroud)
基本上我想要做的就是,当Submit单击按钮时,将输入到text框中的值传递给 aJavaScript Function并记录控制台(现在)。
这看起来已经被问了一百万次,但我读过的问题并没有回答我的问题(我不认为)。
编辑感谢您的所有回复;最大的问题是我试图引用Javascript在表单元素之后调用的外部文件中的函数。
有一些关于 SO 的主题,比如这个建议更改 Webpack,而这个建议设置一个包罗万象的。
我正在使用react-router-dom三个路线;类似的故事,对这里剩余的问题,在/道路工程,但没有/cars或/about不会。
import React, {Component} from 'react';
import {render} from 'react-dom';
import {BrowserRouter, Route, Switch, Link} from 'react-router-dom';
const Home = () => (
<h1>Home</h1>
)
const Car = () => (
<h1>Cars</h1>
)
const About = () => (
<h1>About</h1>
)
render(
<BrowserRouter>
<Switch>
<Route exact path="/" component={Home}/>
<Route exact path="/cars" component={Car}/>
<Route path="/about" component={About}/>
</Switch>
</BrowserRouter>,
document.getElementById('container')
);
Run Code Online (Sandbox Code Playgroud)
我试过在我的 webpack 配置中添加一个 …
javascript reactjs react-router react-router-v4 react-router-dom
我想<input>在我的表中添加一个元素,更具体地说是一个复选框.以下作品:
<tbody key={rule._id}>
<tr>
<td>{rule.deviceId}</td>
{
<input
name="isEnabled"
type="checkbox"
checked={rule.enabled}
/>
}
<td>{rule.name}</td>
</tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)
但它在控制台中产生错误: <input> cannot appear as a child of <tr>
有没有'适当'的方法来做到这一点?
自从我使用navigator.geolocation.getCurrentPosition(如下)制作我的网站以来,控制台中出现错误。我意识到这会在未来的某个时候引起问题,而且由于我只是在玩网络开发,所以我并没有那么担心,但它现在已经完全搞砸了我的小天气应用程序(http:/ /conn3cted.uk.tn/weather.html),因为我似乎无法在 chrome 中使用此功能(它在 firefox 中有效)。我现在另外得到的错误Only secure origins are allowed. 是我能做些什么来解决这个问题吗?我真的不想无缘无故地花钱获得 HTTPS 证书。
getCurrentPosition() and watchPosition() are deprecated on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS.
我试图在目录中创建一个特定文件的数组; 这将通过一些测试用例来确保它符合给定的标准.
我使用的fs.readdir方法,但它并没有回报promise的意思我不能push给array.
我的想法是arr使用我实际想要输出的文件填充array(),然后对该数组执行某些操作.但由于readdir是异步的,我无法链接.then()到它,我的计划被撤销.
我也试过同样的事情readdirSync但无济于事.
const Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs'));
var arr = [];
fs.readdirAsync(folder).then( files => {
files.forEach(file => {
fs.stat(folder + '/' + file, (err, stats) => {
if(!stats.isDirectory()) {
arr.push(file);
return;
}
});
});
})
.then( () => {
console.log(arr);
});
Run Code Online (Sandbox Code Playgroud) 如果创建具有以下内容的文件
const validateEmail = email => {
sendEmail(email);
};
const sendEmail = email => {
return true;
};
module.exports = {
validateEmail,
sendEmail,
};
Run Code Online (Sandbox Code Playgroud)
并尝试测试第二个功能的测试...
it('Should call sendEmail if a valid email is passed', () => {
let sendEmailSpy = sinon.stub(checkEmail, 'sendEmail');
checkEmail.validateEmail('acorrectemail@therightformat.com');
assert.isTrue(sendEmailSpy.called);
});
Run Code Online (Sandbox Code Playgroud)
它仍然调用sendEmail函数,测试失败
但是,如果我这样写module.exports:
module.exports = {
validateEmail(email) {
this.sendEmail(email);
},
sendEmail(email) {
return true;
},
};
Run Code Online (Sandbox Code Playgroud)
它正确地存根...为什么?
javascript ×4
html ×2
jquery ×2
node.js ×2
reactjs ×2
forms ×1
fs ×1
geolocation ×1
react-router ×1
sinon ×1