我正在做一个简单的功能.将所有单词首字母大写为大写,但它根本不起作用,既不显示任何错误:
function formatTitle(input) {
var words = input.split(' ');
for (var i = 0; i < words.length; i++) {
words[i][0] = words[i][0].toUpperCase();
};
return words.join(' ');
};
var newTitle = formatTitle("all words first-letter should be upper case");
document.write(newTitle);Run Code Online (Sandbox Code Playgroud)
提前致谢.
我在调整大小窗口中add remove使用这个类的jQuery代码jQuery:
JS:
$(function () {
$(window).bind("resize", function () {
console.log($(this).width())
if ($(this).width() < 500) {
$('div').removeClass('yellow').addClass('red')
} else {
$('div').removeClass('red').addClass('yellow')
}
})
})
Run Code Online (Sandbox Code Playgroud)
HTML:
<div style="width:300px; height:100px;" class="yellow"></div>
Run Code Online (Sandbox Code Playgroud)
在行动中,这只有在我手动调整窗口大小时才有用但是默认情况下如果设备窗口<500这个功能不起作用.
怎么解决这个问题?!
在这里演示
我想在div中显示已选中的复选框
例如
<input id="checkbox1" type="checkbox"><label for="checkbox1">Checkbox 1</label>
<p>you have selected:</p> <div>checkbox 1</div>
Run Code Online (Sandbox Code Playgroud)
将有超过1个复选框(37),我需要它能够选中所有复选框
我认为这是有道理的
谢谢
我一直在尝试为一些基本的数组方法编写函数,但现在我不再使用splice重新创建shift.任何建议将不胜感激.
MyShift = function (array) {
for (i = array.length - 2; i >= 0; i--) {
array[i] = array[i + 1];
}
--array.length;
};
Run Code Online (Sandbox Code Playgroud) 我熟悉jQuery并制作一个小应用程序,其中红色框在屏幕上移动,用户必须尝试点击它,当用户alert()弹出一个框时,问题是alert()即使在'好的'被压了.我可以阻止它的唯一方法是反复点击'ok'并最终消失.
以下是显示警告框的代码:
function Animate() {
var _newPosition = GetNewPosition();
// Sets new position of div
div.animate({
top: _newPosition[0],
left: _newPosition[1]
}, function () {
div.on('click', function () {
alert('You clicked the box!');
});
Animate();
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的JSFiddle再现问题
我原本以为我可以通过false在调用alert()例如之后返回来解决它:
div.on('click', function () {
alert('You clicked the box!');
return false;
});
Run Code Online (Sandbox Code Playgroud)
但这也不起作用.
我知道这应该是一个简单的事情,但我似乎无法得到我的拇指.
我无法$使用JavaScript/jQuery 替换多个符号,我的JavaScript替换代码如下所示,
var str = $('#amt').html().replace("/\$/g","?");
alert(str);
Run Code Online (Sandbox Code Playgroud)
但它并没有取代所有的发生,请帮我$用?符号替换.
我想编写一个函数来用实际值替换字符串中的变量,例如:
function replaceUrl(url, data) {}
Run Code Online (Sandbox Code Playgroud)
来电者可能是:
replaceUrl('/task/:module?taskId=:taskId#:hash', {
module: 'm1',
taskId: 't1',
hash: 'h1'
});
Run Code Online (Sandbox Code Playgroud)
我认为使用RegEx可能很容易实现这一点,但我对它不是很熟悉.
任何人都可以提供一个简单的方法吗?
我正在研究一个jQuery函数,它在点击时滚动到div.现在它将滚动到顶部,我想知道它们是否是一种方法使其滚动到中心$('.scrollit')而不是顶部,或者可能是一种方法来将其偏移一些像素数量?
$(".playbox").on('click', function () {
$('.scrollit').animate({
scrollTop: $(this).offset().top
}, 1000);
Run Code Online (Sandbox Code Playgroud) 我的ESLint有问题
这是我的功能:
$productItem.filter(function (i, el) {
return el.getBoundingClientRect().top < evt.clientY
}).last()
.after($productItemFull)
Run Code Online (Sandbox Code Playgroud)
以下是ESLint告诉我的内容:
warning Missing function expression name func-names
error Unexpected function expression prefer-arrow-callback
Run Code Online (Sandbox Code Playgroud)
如何解决这个错误?
我希望能够在按键上触发%.到目前为止,我有这个:
$(iframeDocument).find('body').on('keydown', function(event) {
if (event.which == 53) {
alert("% pressed");
}
});
Run Code Online (Sandbox Code Playgroud)
但是,当我按下"5"时它也会触发.我如何区分这两者?
javascript ×9
jquery ×6
html ×4
css ×2
regex ×2
arrays ×1
ecmascript-6 ×1
eslint ×1
function ×1
scroll ×1