尝试显示<tr>如果选择了一个选项
Trying to show a <tr> if an option is selected
我在表单中隐藏了一行,但我希望当我的选择选项设置为"取消"时显示这一行
我就是这样做的:
if($("option[value='Cancelled']").attr("selected") == "selected"){
//Remove New option when Cancelled
$("option[value='New']").remove();
$("nobr").filter(function () { return $.trim(this.childNodes[0].nodeValue) === "Cancel Note"; }).closest("tr").show();
}
在控制台中,我注意到所选属性在切换时不会动态更改,我认为这就是问题所在,但我不知道如何解决这个问题。
代码其余部分:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script><script type="text/javascript">
_spBodyOnLoadFunctionNames.push("hideFields");
//Disables unused Priority radiobox
function hideFields() {
//priority - disable unchecked radiobox
var reg = document.getElementById("ctl00_m_g_0537f4e9_69aa_409a_b5ed_15e3624efeab_ctl00_ctl05_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00");
var high = document.getElementById("ctl00_m_g_0537f4e9_69aa_409a_b5ed_15e3624efeab_ctl00_ctl05_ctl02_ctl00_ctl00_ctl04_ctl00_ctl01");
if(reg.checked == true){
high.disabled=true;
}else{
reg.disabled=true;
}
//On item edit, set status to In Progress if in New
if($("option[value='New']").attr("selected") == "selected"){
//Disable New
$("option[value='New']").remove();
$("option[value='Completed']").remove();
$("option[value='Cancelled']").remove();
//Enable In Progress
$("option[value='In Progress']").attr("selected","selected");
}else if($("option[value='In Progress']").attr("selected") == "selected"){
//Remove New option
$("option[value='New']").remove();
$("option[value='In Progress']").remove();
$("option[value='Completed']").attr("selected","selected");
$("nobr").filter(function () { return $.trim(this.childNodes[0].nodeValue) === "Cancel Note"; }).closest("tr").hide();
}else if($("option[value='Completed']").attr("selected") == "selected" ){
//Remove New option when Completed/Cancelled
$("option[value='New']").remove();
$("nobr").filter(function () { return $.trim(this.childNodes[0].nodeValue) === "Cancel Note"; }).closest("tr").hide();
}else if($("option[value='Cancelled']").is(':selected')){
//Remove New option when Cancelled
$("option[value='New']").remove();
$("nobr").filter(function () { return $.trim(this.childNodes[0].nodeValue) === "Cancel Note"; }).closest("tr").show();
}
//call orderID
orderID();
}
function PreSaveAction() {
//Check is Work Order is claimed
if ($('#content').length == 0){
alert("Please claim Work Order by typing your name or email in NAPA User Field");
return false ;
}
else { return true ;}
}
//I've deprecated this function - Not compatible with Chrome/FF
function findacontrol(FieldName) {
var arr = document.getElementsByTagName("!");
// get all comments
for (var i=0;i < arr.length; i++ )
{
// now match the field name
if (arr[i].innerHTML.indexOf(FieldName) > 0)
{ return arr[i]; }
}
}
//Sets Order ID field to read only in edit form
function orderID() {
//Set the Field to Read only and change its background colour
$("input[title='Order ID']").attr("readonly","true").css('background-color','#F6F6F6');
//call setFocus();
setFocus();
}
//Sets cursor Focus to NAPA users
function setFocus() {
//set focus to NAPA user
document.getElementById("ctl00_m_g_0537f4e9_69aa_409a_b5ed_15e3624efeab_ctl00_ctl05_ctl03_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_upLevelDiv").focus();
}
</script>
我不知道是什么触发了代码块,但出于测试目的,我将在select上使用更改事件。我会这样做:
$("#myselect").on("change", function () {
var $this = $(this);
if ($this.val() == "Cancelled") {
//Remove New option when Cancelled
$this.find("option[value='New']").remove();
$("nobr").filter(function () {
return $.trim(this.childNodes[0].nodeValue) === "Cancel Note";
}).closest("tr").show();
}
});
Fiddle
尝试
if($("option[value='Cancelled']").is(':selected')){
//Remove New option when Cancelled
$("option[value='New']").remove();
$("nobr").filter(function () { return $.trim(this.childNodes[0].nodeValue) === "Cancel Note"; }).closest("tr").show();
}
相关文章:
- 按照选项卡索引的顺序循环一个jQuery选择
- 无法在Ionic select中预先选择最后一个选项
- 一次又一次地在新的和相同的选项卡中打开一个url
- 如果类不是一个选项,如何在使用 jQuery 时控制(避免)嵌套 html 元素的样式
- AngularJS ng选项在选择一个选项后删除了默认的空白值
- 如何为下拉列表的每个选项添加一个属性
- 在下拉列表中选择一个选项的值
- PayPal按钮是否有一个简单的选项,其中金额基于一些用户输入
- 创建了一个选项卡,但点击时不会起作用-jQuery issue/newbie
- 如何通过Primefaces3.5使用JSF2.0验证并在成功的情况下打开一个新的选项卡
- HTML-从mysql生成的选择框中的一个选项更改文本区域的颜色
- 打开一个选项卡,并在firefox网络扩展中向其发出POST请求
- 我如何为列出的选项卡元素编写一个Protractor测试,它会检查它是否's是否处于活动状态
- HTML-使用mysql.php生成一个选择框.我怎样才能更改“;值“;生成的选择框选项的
- 给出<选项>标记一个类?API调用不工作
- 链接到手风琴中的另一个选项卡,嵌入的链接将不起作用
- 如何将数组附加到下拉导航栏并禁用其中的一个选项
- 如何打开一个新窗口或选项卡,并将其提供给javascript执行
- 尝试添加一个选项以使用append进行选择,但没有任何结果
- 多个选择选项一个依赖于另一个