我为密码写了一些验证码,并确认密码是否匹配.此外,还有一个条件是检查我的密码长度是否小于6个字符,如果小于6个字符,则写入/显示错误.但是我的代码无法正常工作:当我切换到字段2时,不检查字段1的条件,如果两个条件都正确,则错误仍然存在.
这是我的代码:
function checkPass()
{
var pass1 = document.getElementById('pass1');
var pass2 = document.getElementById('pass2');
var message = document.getElementById('error-nwl');
var goodColor = "#66cc66";
var badColor = "#ff6666";
if(pass1.value == pass2.value){
pass2.style.backgroundColor = goodColor;
message.style.color = goodColor;
message.innerHTML = "ok!"
}
else{
pass2.style.backgroundColor = badColor;
message.style.color = badColor;
message.innerHTML = " These passwords don't match"
}
if(pass1.length > 5){
pass1.style.backgroundColor = goodColor;
message.style.color = goodColor;
message.innerHTML = "character number ok!"
}
else{
pass1.style.backgroundColor = badColor;
message.style.color = badColor;
message.innerHTML = " you have …Run Code Online (Sandbox Code Playgroud)我有一个简单的表单,并有一个按钮来单击时克隆我的表单.问题是,当我第一次点击按钮时,它工作正常,但是下次它点击时附加了很多div.有没有办法每次点击一个一个地复制?这是我的片段:
$(document).ready(function() {
$(".Add").click(function() {
$(".formi").clone().insertAfter(".formi:last");
});
});Run Code Online (Sandbox Code Playgroud)
.formi {
border: 1px solid #000;
width: 50%;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<span class="Add">Add+</span>
<div class="all">
<form class="formi">
<input type="text" placeholder="name" />
<select name="cars">
<option value="">one</option>
<option value="">two</option>
</select>
<button type="submit">ok</button>
</form>
</div>Run Code Online (Sandbox Code Playgroud)
我有2页,当第一页加载第二页时,那些页面的JavaScript在所有JavaScript之后运行并且加载速度非常慢.我编写了下面的代码来显示微调器,直到第二页完全加载.但是微调器没有用.这是我的代码:
<script>
$('.tourajaxi').html('<i class="fa fa-spinner fa-pulse fa-3x fa-fw" ></i><span class="sr-only">Loading ...</span>');
$(window).load(function() {
$('.tourajaxi').load('/toursajax.bc?gid=325');
});
</script>
Run Code Online (Sandbox Code Playgroud) 所以我有一个文本输入
<input type="text" value="+98912314789" class="telinfo">
Run Code Online (Sandbox Code Playgroud)
有没有办法从头开始保留 4 个字母?我想保持+9891只读状态,用户可以删除除此部分之外的此文本框的所有部分。
有没有办法识别键盘语言?我有一个简单的文本框.我想检查键盘语言.当用户单击文本框时,如果键盘语言与波斯语相反,则用户无法键入任何内容并显示错误:"将键盘语言更改为波斯语",当键盘语言更改时,用户可以键入.
标有NEWFORM的按钮可在单击时创建新表单.每个表单都有一个提交按钮.单击每个表单的提交按钮时,该表单的值将通过AJAX发送.我的代码第一次运行良好,但是当创建并提交新表单时,所有表单的所有值都将一起发送.
这是我的片段:
$(document).ready(function() {
$(".newform").click(function() {
$(".MyForm")
.eq(0)
.clone()
.show()
.insertAfter(".MyForm:last");
});
$(document).on('click', '.MyForm button[type=submit]', function(e) {
e.preventDefault() // To make sure the form is not submitted
$('.MyForm').each(function() {
console.log($(this).serialize())
$.ajax(
$(this).attr('action'),
{
method: $(this).attr('method'),
data: $(this).serialize()
}
)
});
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<span class="newform">NEWFORM+</span>
<div class="all">
<form class="MyForm" method="post">
<input type="text" placeholder="name" value="Aynaz" name="a1" />
<select name="Avg">
<option value="1">1</option>
<option value="2">2</option>
</select>
<button type="submit">Submit</button>
</form>
</div>Run Code Online (Sandbox Code Playgroud)
我有一个带有类名ADD的按钮来创建一个i-frame.
当点击添加我想隐藏按钮,如果该iframe创建.有没有办法用classname隐藏div:iframe创建后添加?
这是我的片段:
$(document).ready(function() {
$(".adding").click(function(e) {
e.preventDefault();
$('#iframeplace').html('<span class="loading">LOADING...</span>');
setTimeout(function() {
$("#iframeplace").html("<iframe name='someFrame' id='someFrame' width='560' height='315'></iframe>");
}, 3000);
})
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="secondpage.html" class="adding">
<div class="ADD">ADD</div>
</a>
<div id="iframeplace"></div>Run Code Online (Sandbox Code Playgroud)
我有一个主页,当文档准备就绪时,我已经通过ajax在其上加载了另一个页面,还有一个按钮,当我单击它时,它会显示警报,并且在第二页中也具有该按钮。但是,当我在该页面中单击该代码时,该代码不起作用?我怎么解决这个问题 ?
因为我不想js codes在第二页上重复?
这是我的第一页代码:
第一页代码:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<div class="captcha" style="border:1px solid red;">
</div>
<div class="details1">cccc</div>
<script>
$(document).ready(function(e) {
$(".captcha").load("/secondpage.htm");
$(".details1").click( function()
{
alert('button clicked');
}
);
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我用类名验证码加载到div中的第二页:
第二页代码:
<html>
<head>
</head>
<body>
<section class="details1"> Details </section>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我编写了以下代码,用于在单击鼠标时禁用鼠标滚动。但是我的代码不起作用,当我用鼠标滚动单击时,它会打开我的链接。
这是我的代码:
$('a').on('mousedown', function(e) {
if (e.which === 2) {
console.log('Disabled');
return false;
}
});Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<a href="#dontwanttoopen"> click here </a>Run Code Online (Sandbox Code Playgroud)
我有很多课程,如果有任何逗号,我想删除它们中的逗号.
我写了下面的代码,但代码无法正常工作.第二个类值替换为第一个值.
var removebox = $(".remove"),
removeboxHtml = removebox.html();
removebox.html(removeboxHtml.replace(/,/g , ''));Run Code Online (Sandbox Code Playgroud)
<html>
<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"></script>
</head>
<body>
<span class="remove">,17500000</span>
<span class="remove">,2479000</span>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
我有两个带有类型文本的输入,当用户开始编写我将数据发送到另一个名为"jsonpage.html"的页面时,我写了一个函数onkeyup.但我的代码的成功部分不起作用.我认为它无法找到div的地址.但在第一部分它可以找到它.我不知道为什么它在成功部分不起作用?如果省略部分"$(this).closest(".main").找到"从成功起作用.但是在我添加这些行之后它没有.
这是我的片段:
$('.country').each(function() {
$(this).on('keyup', function(e) {
var element = $(this).val().length;
if (e.which !== 0 &&
!e.ctrlKey && !e.metaKey && !e.altKey
) {
if (element > 2) {
$(this).closest(".main").find(".mini-loading").css("display", "block")
var val = $(this).val()
val = val.substr(0, 1).toUpperCase() + val.substr(1).toLowerCase();
$(this).val(val)
$.ajax({
url: "jsonpage.html",
type: "get",
contentType: 'application/json; charset=utf-8',
data: {
key: $(this).val()
},
success: function(result) {
$(this).closest(".main").find(".mini-loading").css("display", "none")
$(this).closest(".main").find(".co").empty().html(result)
}
})
}
}
})
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="main">
<div class="city1">
<input type="text" value="" class="country" placeholder="First City" />
<input …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)
我有一个有行的表.在此表中,某些行的跨度为"add"类.当我点击"添加"时,我想动态创建一个新行.代码可以工作,但是当一个新行生成它时,它会在我的表的末尾.如何更改我的代码以仅在单击的行下添加新行,而不是在表的末尾?
这是我的代码:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<table id="prices-table" border="1">
<tr>
<td>1</td>
<td>Title<span class="add"><font color="red">add+</font></span></td>
<td>price</td>
</tr>
<tr>
<td>1</td>
<td>Title </td>
<td>price</td>
</tr>
</table>
<script>
$(document).ready(function () {
$(".add").click(function () {
$(this).closest('#prices-table')
.append('<tr><td>newrow</td><td>newrow</td><td>newrow</td></tr>');
});
})
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)