我有多个输入字段来获取城市.我想在用户输入城市名称的同时将每个单词的第一个字母自动大写,而其余字母则强制为小写.
注意:由于我的要求,CSS text-transform
属性将无法工作,因为它只修改单词的第一个字母 - 如果用户键入大写字母超出第一个字母,则不会调整它.
到目前为止,我有这个JavaScript:
function forceLower(strInput) {
strInput.value=strInput.value.toLowerCase();
}
Run Code Online (Sandbox Code Playgroud)
哪个成功将整个输入转换为小写.
我想将一组嵌套数组转换为一个对象数组,其中包含来自嵌套数组的收集信息:
之前:
var employeeData = [
[
['firstName', 'Bob'], ['lastName', 'Lob'], ['age', 22], ['role', 'salesperson']
],
[
['firstName', 'Mary'], ['lastName', 'Joe'], ['age', 32], ['role', 'director']
]
]
Run Code Online (Sandbox Code Playgroud)
后:
[
{firstName: 'Bob', lastName: 'Lob', age: 22, role: 'salesperson'},
{firstName: 'Mary', lastName: 'Joe', age: 32, role: 'director'}
]
Run Code Online (Sandbox Code Playgroud)
这是我写的解决这个问题的函数,但是我无法看到循环出错的地方:
var employeeData = [
[
['firstName', 'Bob'], ['lastName', 'Lob'], ['age', 22], ['role', 'salesperson']
],
[
['firstName', 'Mary'], ['lastName', 'Joe'], ['age', 32], ['role', 'director']
]
]
function transformData(employeeData) {
let newObject = {};
let …
Run Code Online (Sandbox Code Playgroud)select
当它被禁用时,我似乎无法单击a的父级.我试图让用户通过点击来解锁输入,但它只适用于inputs
.
let $input = $('input')
$input.parent().click(function() {
$input.prop('disabled', false);
})
let $select = $('select')
$select.parent().click(function() {
$select.prop('disabled', false);
})
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
<input name="name" disabled placeholder="click me">
</div>
<div class="parent">
<select name="thing" disabled>
<option value="1">1</option>
</select>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在使用公共类字段语法(handler = () => {...}
)来定义我的所有React组件的事件处理程序,以便我可以使用this
我的组件而不将它们绑定在constructor
.我想知道我可以使用这种语法来使用React生命周期方法吗?用componentWillMount
这种方式说:componentWillMount = () => {...}
如果使用箭头函数定义react的生命周期方法有什么优缺点?
const character = {
name: 'Simon',
getCharacter() {
return this.name;
}
};
const giveMeTheCharacterNOW = character.getCharacter.bind(character);
console.log('?', giveMeTheCharacterNOW);
Run Code Online (Sandbox Code Playgroud)
答案应该是“?simon”//你如何解决这个问题?
function functionOne(x){console.log(x);};
function functionTwo(var1) {
};
functionTwo(functionOne(2));
Run Code Online (Sandbox Code Playgroud)
为什么 functionTwo 在那里工作?它不认为工作,是吗?因为没有手术。
我如何才能在 CSS 中而不是 JS 中获取每个数组并对其进行不同的样式?
count = ['1','2','3','4'];
container = document.getElementById('itemsContainer');
for(i = 0; i < count.length; i++){
container.innerHTML+='<div class="items"></div>';
}
var square= document.getElementsByClassName('items')[2];
square.style.backgroundColor='red';
Run Code Online (Sandbox Code Playgroud)
.items{
margin-top:10px;
width:20px;
height:20px;
background:gold;
Run Code Online (Sandbox Code Playgroud)
<div id="itemsContainer"></div>
Run Code Online (Sandbox Code Playgroud)
我有一个由jQuery/JS填充的输入.目前它使用这样的日期值填充输入,2017-3-7
但我希望它是2017-03-07
.
我在这里有一个jsfiddle:https://jsfiddle.net/ua8rngzw/
代码如下:
(function ($) {
$(document).ready(function() {
var now = new Date();
var created = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();
$('#created').val(created);
});
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
做这种事最简单快捷的方法是什么?
我想在表格单元格中选择一个图像来添加一些添加样式.HTML代码由sharepoint生成,因此图片上没有id/class,我无法编辑它.我不知道如何通过css或javascript选择它.
我想要选择的图片上方的下一课:
<td class="ms-rteTableEvenCol-0" style="width:25%;">?
<a href="/cs/supplyhub/Plants/Forms/AllItems.aspx">
<img src="/cs/supplyhub/SiteAssets/Picture21.png"
alt="Picture21.png" style="margin:5px;width:200px;height:133px;">
</a>
<br>
</td>
Run Code Online (Sandbox Code Playgroud)
我读了很多关于选择器的话题,但是我没有按照我的情况实现它们,所以请帮我一把.目标是添加一些鼠标悬停效果来表示图片作为按钮工作.
我正在使用JavaScript while循环填充HTML控件.我需要从总体中排除字符串值.我正在尝试此代码,但它无法正常工作.我在这做错了什么?
function getWebPropertiesSucceeded()
{
var user = groupOwnerUsers.getEnumerator();
while (user.moveNext())
{
if (user.get_current().get_title() != 'gps\ims sharepoint site collectors')
{
AddRowToTable(user.get_current().get_title());
}
}
}
Run Code Online (Sandbox Code Playgroud)
该gps\ims sharepoint site collectors
值仍在添加到我的控件中.我该如何解决这个问题?