Javascript 我的简单jquery验证不起作用
嘿,伙计们,这是我的代码:Javascript 我的简单jquery验证不起作用,javascript,jquery,html,validation,Javascript,Jquery,Html,Validation,嘿,伙计们,这是我的代码: <script>$('td#view-details').click(function() { var fg = $(this).closest('td').siblings(':first-child').text(); $('#'+fg+'confirm').click(function () { if($('form #' + fg + 'input[name=test]').val() == "")
<script>$('td#view-details').click(function() {
var fg = $(this).closest('td').siblings(':first-child').text();
$('#'+fg+'confirm').click(function () {
if($('form #' + fg + 'input[name=test]').val() == "") {
$('#error_notification').fadeIn(100).delay(1000).fadeOut(100);
return false;
} else {
$(main).text('show');
$('#' + fg).addClass('details').removeClass('active');
$('#success_notification').fadeIn(100).delay(1000).fadeOut(100);
}
});
</script>
<html>
<table width="742" id="redemptions_landing_page" valign="top">
<tr>
<th>ID</th>
<th>Investor Name</th>
<th>Email</th>
<th>Credit</th>
<th>Request Amount</th>
<th>Request Mode</th>
<th>View</th>
</tr>
<tr>
<td>1848719408</td>
<td>arvind</td>
<td>xxxyy@gmail.com</td>
<td>Rs 5000</td>
<td>Rs 300</td>
<td>Cheque</td>
<td id="view-details">show</td>
</tr>
</table>
<form id="1848719408">
<textarea cols="40" rows="10" id="remarks" placeholder="Remarks (enter courier number and courier service provider for confirmed redemptions, enter reason for rejected redemptions)"></textarea>
<h3 class="bbrdt">Redemption Amount</h3>
<input type="text" name="test" id="Amount_For_Investor" placeholder="Amount For Investor" /> <input name="test" type="text" id="courier_charges" placeholder="Courier Charges"/>
<input value="Confirm" type="button" id="1848719408confirm" />
<button id="reject">Reject</button></form>
$('td#查看详细信息')。单击(函数(){
var fg=$(this).closest('td').sides('first child').text();
$('#'+fg+'confirm')。单击(函数(){
if($('form#'+fg+'input[name=test]')。val()=“”){
$(“#错误通知”).fadeIn(100)、delay(1000)、fadeOut(100);
返回false;
}否则{
$(main.text('show');
$('#'+fg).addClass('details').removeClass('active');
$('success_notification').fadeIn(100)、delay(1000)、fadeOut(100);
}
});
身份证件
投资者名称
电子邮件
信用
请求金额
请求模式
看法
1848719408
阿文德
xxxyy@gmail.com
5000卢比
卢比300
支票
显示
赎回金额
拒绝
我想验证文本字段,但它不起作用,当文本字段为空时,会再次显示成功通知,但不会显示错误通知。您缺少已准备好的文档。在绑定
click
事件时,元素尚不存在
试试这个
<script>
$(function(){
// Your code go's here
});
</script>
$(函数(){
//你的密码在这里
});
正如Niels指出的,在开始任何操作之前,您应该等待文档准备就绪,因为您试图访问一些尚未创建的内容
您应该尝试以下方法:
<script>
$(document).ready(function(){
// Your code
});
</script>
$(文档).ready(函数(){
//你的代码
});
您应该始终在函数中包装代码,以确保DOM已加载,如下所示
$(document).ready(function(){
$('td#view-details').click(function() {
var fg = $(this).closest('td').siblings(':first-child').text();
$('#' + fg + 'confirm').click(function() {
if ($('form #' + fg + 'input[name=test]').val() == "") {
$('#error_notification').fadeIn(100).delay(1000).fadeOut(100);
return false;
}
else {
$(main).text('show');
$('#' + fg).addClass('details').removeClass('active');
$('#success_notification').fadeIn(100).delay(1000).fadeOut(100);
}
});
});
虽然我同意将文件包装好是一种好的做法,但我不认为这是您的问题
<script>
$('td#view-details').click(function() {
var fg = $(this).parent().find(":first-child").text();
$('#' + fg + ' confirm').click(function() {
if ($('form #' + fg + ' input[name=test]').val() == "") {
$('#error_notification').fadeIn(100).delay(1000).fadeOut(100);
return false;
}
else {
$(main).text('show');
$('#' + fg).addClass('details').removeClass('active');
$('#success_notification').fadeIn(100).delay(1000).fadeOut(100);
}
});
</script>
$('td#查看详细信息')。单击(函数(){
var fg=$(this.parent().find(“:first child”).text();
$(“#”+fg+“确认”)。单击(函数(){
if($('form#'+fg+'input[name=test]')。val()=“”){
$(“#错误通知”).fadeIn(100)、delay(1000)、fadeOut(100);
返回false;
}
否则{
$(main.text('show');
$('#'+fg).addClass('details').removeClass('active');
$('success_notification').fadeIn(100)、delay(1000)、fadeOut(100);
}
});
var fg=$(this).closest('td')。兄弟姐妹(':first child').text();//此行更改为
var fg=$(this.parent().find(“:first child”).text()
$('#'+fg+'confirm')。单击(函数(){//此行缺少用于确认的空格
if($('form#'+fg+'input[name=test]').val()==“”){//此行缺少输入空间
希望这有帮助!可能是输入错误,但您的
html
标记应该是body
或div
。我已经在local中添加了document ready函数,很抱歉,我忘了放在这里,如果没有这些空格,您的选择器看起来会是:$('1848719408confirm'),这毫无意义。$('form#1848719408input[name=test]')请注意,ID文本和要查找的选择器之间没有spce