我是jQuery的新手.我对这一行有误解:
$('<div></div>').prependTo('body').attr('id', 'overlay');
Run Code Online (Sandbox Code Playgroud)
我可以获得关于这一部分的解释:
$('<div></div>')
Run Code Online (Sandbox Code Playgroud)
先感谢您.
我想这是一个jQuery问题,请看看这里:http://ueno.co/
基本上,我希望能够像这个网站一样滚动到特定的div,怎么做?任何工具或开源jQuery帮我做到这一点?
当用户滚动(向上或向下)时,它将告诉浏览器滚动到特定点.http://ueno.co/
我正在尝试构建一个lib,我需要动态调用函数,具体取决于我在参数中的变量,如下所示
strategies = min
function dispatchRuleToStrategy(strategies)
{
$.each(strategies, function(index, value) {
strategy = "strategy_" + value;
});
}
function strategy_min()
{
// do something
}
Run Code Online (Sandbox Code Playgroud)
我如何调用该函数strategy_min()的dispatchRuleToStrategy()?
我一直在尝试一些没有任何工作的东西.
谢谢你的帮助
我有一个表,我遍历每一行.如果行背景颜色为绿色,并且未选中其类别为linebox的相应复选框,则应在单击提交时显示错误消息.但返回false不起作用,表单正在提交.尽管消息显示.我该如何解决这个问题?下面是代码.
jQuery(document).on('click', '#add-All-button', function () {
$(".rowb").each(function() {
if($(this).css("background-color") == "rgb(71, 163, 71)") {
var ischk = 0;
var row = $(this);
if (row.find('input[class="linebox"]').is(':checked') ) {
ischk++;
}
if(ischk==0) {
alert('Every green colored row should have one of the checkboxes checked.');
return false;
}
}
});
});
Run Code Online (Sandbox Code Playgroud) 我有一个ul包含很多内容的列表li,而且我的输入类型隐藏在少数内容中li.
我想要动态删除或设置display none给那些li没有任何隐藏的东西input.
我怎样才能做到这一点?
这是我的片段:
$('#q li:last-child').remove();Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul id="q">
<li><a class="PageNumber" data-href="home.htm">1</a></li>
<input type="hidden" value="1" class="page" />
<li><a class="PageNumber" data-href="home.htm">2</a></li>
<input type="hidden" value="2" class="page" />
<li><a class="PageNumber" data-href="home.htm">3</a></li>
</ul>Run Code Online (Sandbox Code Playgroud)
我正在尝试为进度条实现这些功能
第一名:
$('.progress').animate(
{
width:'100%'
},
{
duration:3000
}
);
Run Code Online (Sandbox Code Playgroud)
第二名:
function clickme(){
$('.progress-bar').animate(
{
width: '100%'
},
{
duration:3000
}
);
}
Run Code Online (Sandbox Code Playgroud)
如何实现最后一个功能?是否有任何方法来显示百分比的进展.我试图克隆进度,然后将其附加到类pp.它不起作用.
var por = $(".progress").clone();
$(".pp").append(por);
Run Code Online (Sandbox Code Playgroud)
小提琴:
https://jsfiddle.net/amLm9c4o/
编辑:这是添加新的进度条,但连续启动所有进度条.还有一个问题我想在进度条中显示百分比. https://jsfiddle.net/8Lgcfydr/
我试图从jQuery访问JSON结果.
$.ajax({
type: "GET",
url: "http://localhost:8080/App/QueryString.jsp?Query="+query,
contentType:"text/html; charset=utf-8",
dataType: "json",
success: function(json) {
if(data!=""){
console.log(json);
var data = json.Json;
console.log(data);
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是这给了我带有HTML标签的结果.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body> JSON:[Includes the result]</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我得到了json输出,但附带了HTML标签.我只想删除它们并仅获取json结果.
有人可以帮我吗?它与dataType和contentType有关吗?
概述:
在下面的代码中,我应该突出显示 id = "sample" 的 html 元素的最后一次出现,即“这是最后一段”。然而,“这是第一段”却被突出显示。
问题:
1)为什么 $("#sample:last").css("background-color", "yellow") 不突出显示最后一段?
2)当我更改为 $("p#sample:last").css("background-color", "yellow") 时,最后一段会突出显示。为什么这可行,而不是问题 1 中的场景?
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#sample:last").css("background-color", "yellow");
});
</script>
</head>
<body>
<p id="sample">This is the first paragraph.</p>
<p id="sample">This is the second paragraph.</p>
<p id="sample">This is the last paragraph.</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我希望.dot在之前的3秒延迟之后为每个设置动画.dot
.这是我使用的代码.但它不起作用.
var time = 3000;
$(".dot").each(function() {
setTimeout(function() {
$(this).addClass("animate");
$(this).find(".num").addClass("animate");
}, time)
time += 3000;
});
Run Code Online (Sandbox Code Playgroud) 我使用 jQuery select2 来选择多个列表项。
但不幸的是,下面的代码必须将所有 3 个值都加载到选择字段中。但是它只加载第一个项目。
如何将所有 3 个项目加载到 select2 列表中?
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
</head>
<body>
<select id="e1" style="width:400px">
<option value="AL">Alabama</option>
<option value="NY">New york</option>
<option value="WY">Wyoming</option>
</select>
<script>
var selectedValuesTest = ["WY","AL", "NY"];
$(document).ready(function() {
$("#e1").select2({
multiple: true,
});
$('#e1').select2('val', selectedValuesTest);
});
</script>
</body>Run Code Online (Sandbox Code Playgroud)
我想得到并提醒内容,input textbox但它无法正常工作有人可以帮助我吗?
$(document).ready(function() {
var phoneField = $("#PhoneField").val();
$("#SendPhone").click(function() {
alert(phoneField);
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<fieldset>
<h2 class="fs-title">Enter Your Number</h2>
<h3 class="fs-subtitle">This is step 1</h3>
<input type="text" name="email" placeholder="Phone number" id="PhoneField" />
<input type="button" name="next" class="next action-button" value="Next" id="SendPhone" />
</fieldset>Run Code Online (Sandbox Code Playgroud)
我需要将JavaScript变量值传递给另一个JavaScript函数
$("#myTabs form").on('submit', function (e) {
e.preventDefault();
var linkHref = $(this).parents('.tab-pane').attr('id');
$('#myLinks li a').removeClass('active');
$('#myLinks li')
.find('a[href="#' + linkHref + '"]')
.parent()
.next()
.find('a')
.tab('show')
.addClass('active')
.attr('data-toggle', 'tab');
$('a.nav-link').not('.active').css('pointer-events', 'none');
var SAPno = linkHref;
});
$('a.nav-link').not('.active').css('pointer-events', 'none');
Run Code Online (Sandbox Code Playgroud)
For Example var SAPno值需要传递给另一个JavaScript函数
function GetInfo() {
var ID = SAPno;
}
Run Code Online (Sandbox Code Playgroud)
可能吗..
这是我的html
<a href="#" data-value="val1" id="catedit">Link1</a>
<a href="#" data-value="val2" id="catedit">Link2</a>
<a href="#" data-value="val3" id="catedit">Link4</a>
Run Code Online (Sandbox Code Playgroud)
我想要获得具有相同 id 的data-value单击控件。<a>
我尝试了这段代码,但不起作用。
$(document).ready(function() {
$('#catedit').click(function() {
var val = $(this).data('value');
alert(val);
});
});
Run Code Online (Sandbox Code Playgroud)
这是我的小提琴