gpt4 book ai didi

javascript obj.nextSibling.disabled

转载 作者:行者123 更新时间:2023-12-03 08:23:08 25 4
gpt4 key购买 nike

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">





<script language="JavaScript" type="text/javascript"
src="/HRMS/struts/dojo/struts_dojo.js"></script>

<script language="JavaScript" type="text/javascript"
src="/HRMS/struts/ajax/dojoRequire.js"></script>
<link rel="stylesheet" href="/HRMS/struts/xhtml/styles.css" type="text/css"/>

<script language="JavaScript" src="/HRMS/struts/utils.js" type="text/javascript"></script>
<script language="JavaScript" src="/HRMS/struts/xhtml/validation.js" type="text/javascript"></script>
<script language="JavaScript" src="/HRMS/struts/css_xhtml/validation.js" type="text/javascript"></script>
</head>



<body style="margin:0px;">





<!-- body starts here -->

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top">

<!-- welcome Message starts here -->



<!-- PAGE TITLE starts here -->

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="pagetitle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="pagetitle">OT/UT ENTRY</td>
</tr>
</table></td>
</tr>
</table>

<!-- PAGE TITLE ends here -->

<!-- TO display success and error messages -->
<table width="100%" border="0" cellspacing= "0" cellpadding="0">
<tr>
<td colspan="2" class="successmsg"></td>
</tr>
<tr>
<td colspan="2" class="errors"></td>
</tr>
</table>
<!-- End of displaying success or error messages -->

<!-- FORM starts here -->



<script>
var xmlHttp;// global instance of XMLHttpRequest
var counter = 0;


function hoursValidator(empNo,obj){
var mode = document.getElementById("mode");
var selMode = mode.options[mode.selectedIndex].value;
var otUtDate = document.getElementById("attendanceDateStr").value;
var hrs = obj.value;
var resp;

if(hrs === '0'){
alert("Entered hours should be more than 0");
obj.value="";
return false;
}
if(hrs === '12'){
var row = obj.parentNode.parentNode;
var minutes = row.querySelectorAll("id='minutes'");
alert(row);
// alert(mimutes);
// var x = obj.nextSibling.innerHTML;
document.getElementById("minutes").disabled = true;
}


}



</script>
<form id="loadEmployeeOTUTEntry" name="empSuspensionViewSearch" action="/HRMS/hr/loadEmployeeOTUTEntry.action" method="post">
<input type="hidden" name="cutOff" value="21-OCT-2015 00:00:00" id="cutOff"/>
<input type="hidden" name="lastRunOtut" value="10-NOV-2015 11:50:04" id="cutOff"/>

<fieldset class="fieldset">

<legend class="legendtitle">OT/UT - ENTRY</legend>
<table width="100%" border="0" cellspacing= "0" cellpadding="0">
<tr>
<td class="labelone2">Branch:<span class="mandatory">*</span></td>
<td class="dataone1">

<select name="hrOtUtRegisterDtl.branchCode" id="branch" class="txtbox_mandatory">
<option value="3102" selected="selected">AL AIN MALL ALAIN</option>


</select>
</td>

<td class="labelone2">Department:<span class="mandatory">*</span></td>
<td class="dataone1" colspan=2>

<select name="hrOtUtRegisterDtl.deptCode" id="dept" class="txtbox_mandatory">
<option value="16" selected="selected">CASH EXPRESS</option>


</select>
</td>
</tr>
<tr align="center">
<td class="labelone1" width="15%">Date:<span class="mandatory">*</span></td>
<td class="dataone2" width="35%"><input type="text" name="hrOtUtRegisterDtl.attendanceDateStr" value="12-Nov-2015" id="attendanceDateStr" class="txtbox" onblur="return dateValidator(id);"/>
</td>
<td class="labelone2">Action:<span class="mandatory">*</span></td>
<td class="dataone1" colspan = 2>

<select name="hrOtUtRegisterDtl.otUtFormType" id="mode" class="txtbox_mandatory" onchange="getEmployees();">
<option value="OT" selected="selected">OVER TIME</option>
<option value="UT">UNDER TIME</option>


</select>
</td>
</tr>
<tr>
<td class="buttonband" colspan="4">
<input type="button" class="btn" value="Search" onclick="getEmployees();"/> &nbsp;
<input name="button" type="reset" class="btn" value="Clear" onclick="reload();">
</td>
</tr>
<div
id="divSearchResult"

class="csShow"

>

<script>document.getElementById("attendanceDateStr").readOnly = true;</script>
<br><table>
<tr>
<td class="Htd_one1" width="5%"><div align="center">Serial Number</div></td>
<td class="Htd_one1" width="30%"><div align="center">Employee Number</div></td>
<td class="Htd_one1" width="30%"><div align="center">Employee Name</div></td>
<td class="Htd_one1" width="20%"><div align="center">Hours</div></td>
<td class="Htd_one1" width="20%"><div align="center">Minutes</div></td>
</tr>

<tr class="oddrow">
<td class="dataone2" align="center">
<div align="center">1</div>
</td>
<td class="dataone2"><div align="center">
11727</div>
<input type="hidden" name="hrOtUtRegisterDtl.empNum" value="11727" id="empNum"/>
</td>
<td class="dataone2">
OBAIDULLAH KHAN MOHAMMED YAQOOBULLAH KHAN MOHAMMED
<input type="hidden" name="hrOtUtRegisterDtl.empName" value="OBAIDULLAH KHAN MOHAMMED YAQOOBULLAH KHAN MOHAMMED" id="empName"/>
</td>
<td class="dataone2" >
<input type="text" name="hrOtUtRegisterDtl.hoursStr" value="" id="hours" class="txtbox_mandatory" onblur="hoursValidator('11727',this);" onkeydown="return allowNumberOnly(event);"/>

</td>
<td class="dataone2" >
<input type="text" name="hrOtUtRegisterDtl.minutesStr" value="" id="minutes" class="txtbox_mandatory" onblur="minsValidator('11727',this);" onkeydown="return allowNumberOnly(event);"/>

</td>
</tr>

<tr>
<td class="buttonband" colspan="4">
<input type="button" class="btn" value="Submit" onclick="saveOTUT();"/> &nbsp;
</td>
</tr>
</table>

</div>

</table>
</fieldset>

</form>





<!-- FORM ends here -->
</td>
</tr>
</table>

<!-- body Ends here -->


</body>
</html>

enter image description here

我有多行显示小时和分钟。如果用户在一行中输入小时数为 12,则应对该行禁用分钟数。

//obj.nextSibling.disabled = true; 
//obj.nextSibling.readonly = true;

不工作。还有其他语法可以实现吗?

<script>
function hoursValidator(empNo,obj){
var hrs = obj.value;

if(hrs === '12'){
obj.nextSibling.disabled = true;
obj.nextSibling.readOnly = true;
document.getElementById("minutes").disabled = true;
}
</script>

<s:iterator status="stat" value="empList" id="empList">
<tr>
<td >
<s:property value="empName" />
</td>
<td>
<s:textfield name="hoursStr" value = "%{hoursStr}" onblur="hoursValidator('%{empNum}',this);" onkeydown="return allowNumberOnly(event);" id="hours"/>
</td>
<td class="dataone2" >
<s:textfield name="minutesStr" value = "%{minutesStr}" onblur="minsValidator('%{empNum}',this);" id="minutes" onkeydown="return allowNumberOnly(event);"/> </td>
</tr>
</iterator>

最佳答案

首先,您需要确保 hoursValidator() 函数中的 obj 实际上是 hoursStr 对象。您报告的一些情况表明 obj 设置不正确。

如果 objhoursStr 对象,那么您可以像这样获取同一行中的 minutesStr 对象:

var row = obj.parentNode.parentNode;
var minutes = row.querySelectorAll("[name='hrOtUtRegisterDtl.minutesStr']");
minutes[0].disabled = true;
minutes[0].readonly = true;

您不能使用 nextSibling,因为目标对象位于不同的表格单元格中 - 它不是同一单元格中的同级对象。

我发现您在每一行中都使用 id="months"id="hours"。 ID 在整个文档中必须是唯一的,这样对于每行中重复的结构将不起作用。这就是为什么我没有在上面推荐的代码中使用这些 id 值。

使用您的 HTML 进行工作演示:http://jsfiddle.net/jfriend00/x3djcmf9/

<小时/>

而且,如果您只有一行 id="months",那么您也可以执行以下操作:

var minutes = document.getElementById("minutes");
minutes.disabled = true;
minutes.readonly = true;

工作演示:http://jsfiddle.net/jfriend00/6dLgkm5v/

附注如果数字被编辑为“12”以外的其他内容,您可能需要重新启用该字段。

关于javascript obj.nextSibling.disabled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33665269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com