HTML
HTML
<div class="col-sm-1">
<a class="a" ng-click="aa()">
<span name="yesLink"></span>
</a>
</div>
<div class="col-sm-1">
<a class="a" ng-click="bb()">
<span name="NoLink"></span>
</a>
</div>
<div id="nnn" class="col-sm-7" align="left" >
<p ng-show="yes"> Text for yes</P>
<p ng-show="no"> Text for no</P>
</div>
JS
JS
yesLink.onclick()=function()
{
scope.yes=true;
}
noLink.onclick()=function()
{
scope.no=true;
}
I have used the above code.I want to display message according to click.But it is not working. What is wrong with this code? If yesLink is clicked, "Text for yes" should come and if NoLink is clicked ,"Text for no" should come.
我已经使用了上面的代码。我想根据点击显示消息。但它不起作用。这段代码有什么问题?如果单击yesLink,则应显示“是的文本”,如果单击“无链接”,则应显示“文本为否”。
4 个解决方案
#1
2
I see Angular is being used in the above code so the HTML part will be
我看到Angular正在上面的代码中使用,所以HTML部分将是
your controller part should be something like
你的控制器部分应该是这样的
Considering bb() and aa() as a click function
将bb()和aa()视为单击函数
$scope.bb = function(){
$scope.yes = true;
}
$scope.aa = function(){
$scope.no = true;
}
#2
2
I think, there is no need to add onclick method. just do this
我认为,没有必要添加onclick方法。就这样做
<div class="col-sm-1">
<a class="a" ng-click="yes=true">
<span name="yesLink"></span>
</a>
</div>
<div class="col-sm-1">
<a class="a" ng-click="yes=false;">
<span name="NoLink"></span>
</a>
</div>
<div id="nnn" class="col-sm-7" align="left" >
<p ng-show="yes"> Text for yes</P>
<p ng-hide="yes"> Text for no</P>
</div>
#3
0
The value you are checking against is a boolean but the value you are assigning to the variable is a string. You have two options>
您要检查的值是布尔值,但是您为变量赋值的值是一个字符串。你有两个选择>
OPTION 1: Tell the ng-hide/show value to look for the string value, ng-show="yes === 'true'".
选项1:告诉ng-hide / show值查找字符串值,ng-show =“yes ==='true'”。
OPTION 2: In your function swap out the strings for boolean values, scope.yes = true and NOT scope.yes="true"
选项2:在你的函数中换掉布尔值的字符串,scope.yes = true而不是scope.yes =“true”
#4
0
No need for jquery, you can use ng-click
, ng-click triggers the function in controler
不需要jquery,你可以使用ng-click,ng-click触发controler中的函数
<div class="col-sm-1">
<a class="a" ng-click="aa()">
<span name="yesLink"></span>
</a>
</div>
<div class="col-sm-1">
<a class="a" ng-click="bb()">
<span name="NoLink"></span>
</a>
</div>
<div id="nnn" class="col-sm-7" align="left" >
<p ng-show="yes"> Text for yes</P>
<p ng-show="no"> Text for no</P>
</div>
JS
JS
scope.aa() = function(){
scope.yes = true;
}
scope.bb() = function(){
scope.no = true;
}
#1
2
I see Angular is being used in the above code so the HTML part will be
我看到Angular正在上面的代码中使用,所以HTML部分将是
your controller part should be something like
你的控制器部分应该是这样的
Considering bb() and aa() as a click function
将bb()和aa()视为单击函数
$scope.bb = function(){
$scope.yes = true;
}
$scope.aa = function(){
$scope.no = true;
}
#2
2
I think, there is no need to add onclick method. just do this
我认为,没有必要添加onclick方法。就这样做
<div class="col-sm-1">
<a class="a" ng-click="yes=true">
<span name="yesLink"></span>
</a>
</div>
<div class="col-sm-1">
<a class="a" ng-click="yes=false;">
<span name="NoLink"></span>
</a>
</div>
<div id="nnn" class="col-sm-7" align="left" >
<p ng-show="yes"> Text for yes</P>
<p ng-hide="yes"> Text for no</P>
</div>
#3
0
The value you are checking against is a boolean but the value you are assigning to the variable is a string. You have two options>
您要检查的值是布尔值,但是您为变量赋值的值是一个字符串。你有两个选择>
OPTION 1: Tell the ng-hide/show value to look for the string value, ng-show="yes === 'true'".
选项1:告诉ng-hide / show值查找字符串值,ng-show =“yes ==='true'”。
OPTION 2: In your function swap out the strings for boolean values, scope.yes = true and NOT scope.yes="true"
选项2:在你的函数中换掉布尔值的字符串,scope.yes = true而不是scope.yes =“true”
#4
0
No need for jquery, you can use ng-click
, ng-click triggers the function in controler
不需要jquery,你可以使用ng-click,ng-click触发controler中的函数
<div class="col-sm-1">
<a class="a" ng-click="aa()">
<span name="yesLink"></span>
</a>
</div>
<div class="col-sm-1">
<a class="a" ng-click="bb()">
<span name="NoLink"></span>
</a>
</div>
<div id="nnn" class="col-sm-7" align="left" >
<p ng-show="yes"> Text for yes</P>
<p ng-show="no"> Text for no</P>
</div>
JS
JS
scope.aa() = function(){
scope.yes = true;
}
scope.bb() = function(){
scope.no = true;
}