Javascript 需要根据条件隐藏选定的图元
我有各种选项的下拉菜单 刚出现的 进行中 命令 未订购 完整的 取消 我有一个表单,当状态为新时,我需要隐藏ETA行,然后为任何其他状态启用它。这就是我所尝试的:Javascript 需要根据条件隐藏选定的图元,javascript,jquery,jquery-selectors,global-variables,variable-declaration,Javascript,Jquery,Jquery Selectors,Global Variables,Variable Declaration,我有各种选项的下拉菜单 刚出现的 进行中 命令 未订购 完整的 取消 我有一个表单,当状态为新时,我需要隐藏ETA行,然后为任何其他状态启用它。这就是我所尝试的: var progress, ordered, unordered, completed, cancelled, reg, high, user, trimUser, etaDate, etaRow, etaHour, etaMinutes; function initiate() { //declaring necessar
var progress, ordered, unordered, completed, cancelled, reg, high, user, trimUser, etaDate, etaRow, etaHour, etaMinutes;
function initiate() {
//declaring necessary variables
declaration()
}
function declaration(){
//Declaration of variables for status changes
sNew = $("option[value='New']");
progress = $("option[value='In Progress']");
ordered = $("option[value='Ordered']");
unordered = $("option[value='Unordered']");
completed = $("option[value='Completed']");
cancelled = $("option[value='Cancelled']");
//Declaring variables for priority changes
reg = $('input[value="ctl00"]');
high = $('input[value="ctl01"]');
//Declaring current user using SPServices
user = $().SPServices.SPGetCurrentUser({
fieldName: "Name",
debug: false
});
//Declaring variables for ETA field manipulation
etaRow = $("nobr").filter(function () { return $.trim(this.childNodes[0].nodeValue) === "ETA"; }).closest("tr");
etaDate = $('input[title="ETA"]');
etaHour = $("[id$=DateTimeFieldDateHours]");
etaMinutes = $("[id$=DateTimeFieldDateMinutes]");
}
function hideETA(){
//hide ETA options
etaRow.hide();
if(sNew.not(:checked)){
alert('CP1');
eta.show();
}
}
所以我尝试的方法是,一开始隐藏它,因为新是默认值,然后当它不是新的时,显示它
编辑:
我想我已经解决了,在@Richard使用if语句和选择器提供帮助后,我就是这样做的:
function setETA(){
//Hide, Display and Disable ETA based on stages
if(sNew.is(":checked")){
etaRow.hide();
}else if (progress.is(":checked")){
//do nothing, should be already showing
}else{
etaDate.attr("readonly","true").css('background-color','#F6F6F6');
etaHour.attr("disabled","disabled");
etaMinutes.attr("disabled","disabled");
}
}
2可能性:
显示=无
删除该选项
对于显示方法:
马上,换成ifsNew。不是:检查到if!新:是的。添加引号并使用.is…Done。只是想知道,什么是。不这样做,我以为是一样的。那么你的实际相关HTML是什么?返回布尔值。这是一张简单有效的支票。not返回原始输入的重复子集。例如:$li.not.selected.css。。。。这个.not可能和引号一起工作,但它没有按照你的想法工作。哦,好的,听起来不错,谢谢。
// Hide the Option
var opt = $('option[value=New]');
opt.css('display','none');
if( opt.parent().val() == 'New' )
opt.next().attr("selected", "selected");
// Show the Option
var opt = $('option[value=New]');
opt.css('display','');