我有两个这样的文本框,在textbox1中输入一些文本后,textbox2将被禁用,这是有效的。第二个要求是,禁用后,将鼠标悬停在第二个文本上时,应显示“您只能在一个文本框中输入”。
有人可以帮我吗..,
答案 0 :(得分:1)
这是我的解决方案,您必须将带条件的ng-disables设置为firs要求,并使用angularjs表达式输入标题:
html
class Foo extends App {
println("Foo")
def bar = {}
}
class FooX extends Foo {
println("Foo2")
}
object Foo2 extends FooX {
}
js
<div ng-app="myApp">
<div ng-controller="validateController as vm">
<input type="text" ng-model="vm.first" >
<input type="text" ng-model="vm.second"
ng-disabled="!!vm.first" title="{{vm.first ? 'You can enter only in one textbox': ''}}">
</div>
</div>
这是codepen solution
答案 1 :(得分:0)
这是代码:
<html>
<body>
<input type="text" id="firstbox" onmouseleave="disablesecond(3)" onmouseover="disablesecond(2)">
<input type="text" id="second" onmouseleave="disablesecond(3)" onmouseover="disablesecond(1)">
<p id="info"></p>
<script>
function disablesecond(needtoblock){
if(needtoblock == 1){
document.getElementById("firstbox").disabled = true;
document.getElementById("second").disabled = false;
document.getElementById("info").innerHTML= "Only one box!";
}else if(needtoblock == 2){
document.getElementById("second").disabled = true;
document.getElementById("firstbox").disabled = false;
document.getElementById("info").innerHTML= "Only one box!";
}else{
document.getElementById("firstbox").disabled = false;
document.getElementById("second").disabled = false;
document.getElementById("info").innerHTML= "";
}
}
</script>
</body>
</html>