【发布时间】:2016-02-17 20:54:37
【问题描述】:
我的 Internet Explorer 有问题(目前是 v 10)我有 2 个单选按钮是/否和一个确认框,如果用户单击取消,该值应该恢复到原始值
例如:yes 是默认值。用户单击否,弹出显示 - 用户取消应返回是。 问题...值没有改变它停留在否
我的代码在 FireFox 和 GoogleChrome 上运行良好
见jsFiddle(我认为你必须在IE10中打开它......)
enter code here
https://jsfiddle.net/grosjambon/nxy0g1cg/
如果jsfiddle不工作请评论
EDIT1
在这里找到了一些有用但有一点问题的东西。当我尝试以 Knockout 在 Click Binding 中执行的方式将多个参数绑定到函数时,当“人员”确认更改值时,单选按钮中的值不会更新(两个单选按钮内部都没有)
HTML
<input class="radio-inline" type="radio" data-bind="click: function(data,event){confirmCheck2(lang('Options1'),false, '1Group0', data, event)}, checked: IsSomething,checkedValue: true" />
<input class="radio-inline" type="radio" data-bind="click: function(data,event){confirmCheck2(lang('Options1'),true, '1Group0', data, event)}, checked: IsSomething,checkedValue: false" />
ViewModel(Knockout) Ok confirm 有问题的方法(两个radio都是空的)
m.confirmCheck2 = function (propertyName, inputValue, stepName, data, event) {
console.log(event);
if (!confirm("Are you sure?")) {
event.stopImmediatePropagation();
return false;
}
return true;
}
有效但没有额外属性的方法
html
<input class="radio-inline" type="radio" data-bind="click: confirmCheck, checked: IsITARAndCGP,checkedValue: true" />
视图模型
m.confirmCheck = function (data, event) {
console.log(data);
console.log(event);
if (!confirm("Are you sure?")) {
event.stopImmediatePropagation();
return false;
}
return true;
}
EDIT 2 所以在回复之间,我找到了使用 Roy 的旧答案的解决方案。 P.S 如果我们使问题复杂化:所以我有多个属性 m.Property1 m.Property2,m.Property3。当 1 为 True 时,所有其他均为 false,如果 True 属性变为 False,则所有内容均为 false。只有 1 个值可以为真。
因此,当您更改值时,使用 RoyJ 的先前回答,它将触发每个具有 Confirm Popup 的属性的订阅,因为所有 3 个属性都会触发相同的确认。
var showPopup = true;
m.Property1.subscribe(function () {
var inputValue = m.Property1();
if (showPopup) {
if (confirm(f.lang("Message"))) {
showPopup = false;//Disable showPopup because we set value inside resetValueFunction
resetValueWithCondition("Property1"), inputValue);
} else { // if cancel
showPopup = false;
m.Property1(!inputValue);
return true;//Exit code
}
}
showPopup = false;//Disable showPopup because we set value inside resetValueFunction
resetValueWithCondition("Property2", inputValue);
showPopup = true;
});
m.Property2.subscribe(function () {
var inputValue = m.Property2();
if (showPopup) {
if (confirm(f.lang("Message"))) {
showPopup = false;//Disable showPopup because we set value inside resetValueFunction
resetValueWithCondition("Property2", inputValue);
} else { // if cancel
showPopup = false;
m.Property2(!inputValue);
return true;//Exit code
}
}
showPopup = true;
});
函数resetValueWithCondition
function resetValueWithCondition(propertyName,inputValue) {
if (!m.Property1() && !m.Property2()) {//In this If I hide every field in my form and set Property 1 and Property2.... to false.
//m.Step1Visiblity(false);
resetFormValueAfterStepPosition('1Group0');//Reset all form field
setPropertyValue(false, false);//Here is simply m.Property1(false) etc...
} else {
resetFormValueAfterStepPosition('1Group0');//Reset all form field
if (inputValue == true) {//Only perform this method if Property goes to True, otherwise don't execute (otherwise it trigger the confirm box multiple time when I Set Propertyvalue
m.visibilityLogic(propertyName);//Set PropertyValue to either true,false or false,true if is it property1 or property2
}
}
}
【问题讨论】:
-
这是错的小提琴,因为它与你的问题无关
-
现在应该好了?我编辑了一个链接。
标签: javascript internet-explorer knockout.js