我正在使用此脚本来限制textarea上第1-3行的字符.它适用于Firefox和Chrome.但在IE8中,它在使用filter()方法的行上显示错误:"对象不支持此属性或方法".
这是代码:
var result = jQuery('#result');
var my_textarea = jQuery('#mytext');
my_textarea.on('keyup', function(event){
var el = jQuery(this);
var lines = el.val().split('\n').length;
var chars = el.val().split('').filter(function(v){
return v != '\n';
}).length;
result.html('You have ' + lines + ' lines and ' + chars + ' chars');
if ((lines === 1 && chars > 20) || (lines === 2 && chars > 40) || (lines === 3 && chars > 60)) {
my_textarea.val( my_textarea.val() + "\n");
}
});
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
I did something like this to initially hide the body scrollbar, and then show it when a link is clicked:
$('body').css('overflow', 'hidden');
$('#site').click(function(e) {
$('#wrapper').remove();
$('body').css('overflow', 'scroll');
return false;
});
Run Code Online (Sandbox Code Playgroud)
At first, it does hide the scrollbar and just shows a scrollbar for the overlay (absolutely positioned div (#wrapper)) but when I click on the link (#site) to show the scrollbar again (and remove the overlay), it now shows two scrollbars: one is working, the other is disabled.
<div …Run Code Online (Sandbox Code Playgroud) 我正在为我的按钮使用a:focus伪类(按下时).它在Firefox上工作正常,但它不会改变它在Chrome中的状态.有没有解决方法?
CSS:
.btn:focus {
box-shadow: 1px 1px 1px #586601 inset;
text-shadow: -1px -1px 1px #000000;
}
Run Code Online (Sandbox Code Playgroud)
(这是一个带有"btn"类的输入标签.)
如果文本居中对齐,如何对齐背景图标图像?就像文本前面的小图标一样。如果它不是中心对齐,我可以使用类似的东西:
p {
background: url(image.jpg) no-repeat 0 0;
padding-left: 40px;
}
Run Code Online (Sandbox Code Playgroud)
但如果我像这样居中对齐:
p {
background: url(image.jpg) no-repeat 0 0;
padding-left: 40px;
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
背景保留在左角,而文本居中(因此它们之间有很大的间隙)。可以使用背景位置,但是,如果屏幕的尺寸与我使用的尺寸不同,则背景将与文本重叠。
你可以查看 jsFiddle 演示:
这是我们使用的幻灯片:
http://www.littlewebthings.com/projects/blinds/
这是JS文件:
http://www.littlewebthings.com/projects/blinds/js/jquery.blinds-0.9.js
但是,此幻灯片显示没有使其自动浏览每个图像的设置.您仍然必须单击它下面的数字才能看到图像.有人知道要添加到javascript代码中的内容,以使其自动浏览每个图像吗?
谢谢!
我的一个表中有一个名为"publicationDate"的字段,其数据类型是date.但是,当我创建一个应该显示今天日期的查询时,我遇到了如何格式化它的问题.它总是显示出来0000-00-00.
这是我的变量:
$today = date("F j, Y, g:i a");
Run Code Online (Sandbox Code Playgroud)
这是我的查询:
$query = "INSERT INTO articles (summary, publicationDate) VALUES ('{$content}', '{$today}')";
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我的常见问题解答组件中有这样的状态:
this.state = {
faqs: [
{
question: "Some question string",
answer: "Some answer string"
},
{
question: "Some question string",
answer: "Some answer string"
}
]
};
Run Code Online (Sandbox Code Playgroud)
我在渲染方法中循环以显示每个常见问题解答集。但是,我的“answer”属性需要包含<p></p>标签,如下所示:
{
question: "Some question string",
answer: "<p>Some answer string</p> <p>Some answer string</p>"
}
Run Code Online (Sandbox Code Playgroud)
我如何在反应中实现这一目标?
场景是:
Error: GraphQL error: unauthorized.onErrorfromapollo-link-error方法捕获错误,并且可以从中调用refreshToken()(它需要过期的 jwt)。这是目前我的代码:
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors) {
refreshToken();
}
});
const link = ApolloLink.from([errorLink, terminatingLink]);
Run Code Online (Sandbox Code Playgroud)
我们如何改进此流程,以便在用户发出请求时刷新令牌而不会出错?如果请求导致错误,则类似请求将被“搁置”,然后一旦刷新令牌,就会对其进行处理。但我不知道如何做到这一点。
或者我们有没有其他方法可以改进这个流程?
我想将 SOLID 原则应用于处理太多“用例”的反应组件。举个例子,假设我有一个组件,它的主要职责是渲染一个像这样的表:
return (
<Table dataSource="" name={tableName} />
)
Run Code Online (Sandbox Code Playgroud)
这是该表的非常简单的表示。但主要的复杂点是 prop dataSource。在这个<Table>组件内部,我实际上有很多逻辑/if-else 条件来满足dataSource组件中散落的标志,因为它们dataSource可以采用许多不同的形状/对象结构。有些非常相似,可以抽象出来,而有些则非常具体(甚至可能只是一个键不同)。
例如:
const tableName = `${
dataSource === 'dataSourceA'
? dataSourceName
: dataSourceName.name
}`;
Run Code Online (Sandbox Code Playgroud)
这只是一个例子。想象一下,一些dataSource有其name财产嵌套深3个级别。然后其他dataSource键甚至会有不同的名称(尽管我需要渲染的结果数据实际上是相同的)。不仅如此,根据dataSource,我可能需要调用不同的端点来执行某些功能(同样,该函数具有相同的目的,只是端点可以不同)。因此,在同一个组件中,我将具有如下功能:
const exportTable = () => {
if(dataSource === 'dataSourceA') {
// use endpoint A
} else if (dataSource=== 'dataSourceB') {
// use endpoint B
} else {
// use endpoint C
}
}
Run Code Online (Sandbox Code Playgroud)
重构此类组件并使其更易于维护的最佳方法是什么?稍后,我们可以有 10 种类型,dataSources …
refactoring javascript-objects data-structures solid-principles reactjs
我正在使用响应式图像技术,即根据屏幕分辨率/大小将最大宽度设置为100%以调整图像大小.但是,当我将图像放在具有百分比宽度的div中时,图像看起来不清晰(因为我推测,它已经通过浏览器调整大小).图像上的文字非常模糊.有没有办法让它看起来清脆?或者至少让它在最常见的屏幕尺寸上看起来很清晰?
CSS:
img {
max-width: 100%;
height: auto;
}
.img-container {
width: 57%;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="img-container">
<img src="[img source]" width="700" height="500" />
</div>
Run Code Online (Sandbox Code Playgroud)