gpt4 book ai didi

javascript - 在 ng-click 函数中传递参数不起作用

转载 作者:行者123 更新时间:2023-12-03 04:59:41 24 4
gpt4 key购买 nike

我真的是 javascript 和 angularjs 的初学者,我陷入了某种工作,我不知道出路是什么。请有人帮助我纠正我在 Angular 和 javascript 方面的错误。这是我的代码 Angular 和 html 页面。提前谢谢

JAVASCRIPT 和 ANGULARJS 部分

<script>
// Accordion
$scope.myFunction = function(id) {
//alert ("The id is"+id);
$scope.x = id;
if ($scope.x.className.indexOf("w3-show") == -1) {
$scope.x.className += " w3-show";
$scope.x.previousElementSibling.className += " w3-theme-d1";
} else {
$scope.x.className = $scope.x.className.replace("w3-show", "");
$scope.x.previousElementSibling.className =
x.previousElementSibling.className.replace(" w3-theme-d1", "");
}
}
</script>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
alert("controller is getting called");
$scope.loadquestions = function() {

alert("in the question section");

$http({
method: "POST",
url: "qpedia_php.php",
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function(response) {


alert("The question response is" + response.data);
$scope.questions = response.data;


});

},



});
</script>

HTML 部分

<div class="w3-row w3-accordion">
<?php ?>
<button type="button" style="margin-right:75%;margin-left:8.33333%;" ng-click="myFunction('Demsl{{question.id}}')" class="w3-btn w3-theme-d2 w3-margin-bottom"><i class="fa fa-comment"></i>ANSWERS({{question.noofanswers}})</button>
<div id="Demsl{{question.id}}" class="w3-accordion-content w3-padding" ng-init="loadanswers();">
<div class="w3-row">

<div class="w3-col s10" style="margin-right:8.33333%;">
<form method="post">

<input type="hidden" name="q_user_id" value="<?php //echo $userid?>">
<input type="hidden" name="q_id" value="{{answer.qid}}">

<input class="w3-input w3-border" type="text" name="answer" placeholder="GIVE YOUR ANSWER HERE">
<input type="submit" name="post_answer" value="" id="inputSuccess4" style="display:none;">
</form>
</div>
</div>

<div class="w3-row-padding w3-card-4" style="margin:16px;" ng-repeat="answer in answers">
<div class="w3-row" style="word-wrap:break-word">
<div class="w3-col s2 w3-padding-large">

<img src="{{answer.userpic1}}" class="w3-circle w3-margin-right" style="height:45px;width:45px" alt="Avatar"><span class="w3-text-white"></span></a>


</div>
<div class="w3-col s4" style="">
<h4><b>{{answer.answername}}</h4></b>

</div>

</div>

<div class="w3-row">
<div class="w3-col s8" style="word-wrap:break-word;margin-left:16.66666%;margin-right:16.66666%;">
{{answer.ans}}
</div>
</div>
</br>
<div class="w3-row w3-container">
<div class="w3-col s2" style="margin-left:16.66666%;">

<form method="post">
<input type="hidden" name="q_id" value="{{answer.qid}}" style="width:100px;">
<input type="hidden" name="answer_id" value="{{answer.answerid}}" style="width:100px;">


<button type="submit" name="answerlike" class="w3-btn w3-theme-d1 w3-margin-bottom"><i class="fa fa-thumbs-o-up"></i>|{{answer.noofanswerlike}}</button>
</form>



</div>

<div class="w3-col s2">



<form method="post">
<input type="hidden" name="q_id" value="{{answer.qid}}" style="width:100px;">

<input type="hidden" name="user_id" value="<?php //echo $userid;?>" style="width:100px;">
<input type="hidden" name="answer_id" value="{{answer.answerid}}" style="width:100px;">
<button type="submit" name="answernounlike" class="w3-btn w3-theme-d1 w3-margin-bottom"><i class="fa fa-thumbs-o-down"></i>|{{answer.noofanswerunlike}}</button>
</form>

</div>
</div>
<div class="w3-accordion w3-row">

<button type="button" style="margin-right:75%;margin-left:18%;" ng-click="myFunction('Deoslanswer.answerid')" class="w3-btn w3-theme-d2 w3-margin-bottom"><i class="fa fa-comment"></i>REPLIES({{answer.noofreplies}})</button>


<div class="w3-accordion-content w3-padding" id="Deosl{{answer.answerid}}" ng-init="loadreplies()">
<div class="w3-row">

<div class="w3-col s10" style="margin-right:8.33333%;">
<form method="post">

<input type="hidden" name="q_user_id" value="<?php //echo $userid;?>">
<input type="hidden" name="q_id" value="{{answer.qid}}">
<input type="hidden" name="answer_id" value="{{answer.answerid}}">

<input class="w3-input w3-border" type="text" name="reply" placeholder="GIVE YOUR REPLY HERE">
<input type="submit" name="post_reply" value="" id="inputSuccess4" style="display:none;">
</form>
</div>
</div>

<div class="w3-row-padding w3-card-8" style="margin:16px;" ng-repeat="reply in replies">
<div class="w3-row">
<div class="w3-col s2">

<img src="{{reply.userpic}}" class="w3-circle w3-margin-right" style="height:45px;width:45px" alt="Avatar"><span class="w3-text-white"></span></a>



</div>
<div class="w3-col s4">
<h5><b>{{reply.answerreplyname}}</b></h5>
</div>


</div>
<div class="w3-row">
<div class="w3-col s8" style="word-wrap:break-word;margin-right:16.66666%;margin-left:16.66666%;">
<p>{{reply.answerreply}}</p>
</div>
</div>

</div>

</div>
</div>
</div>

</div>
</div>

最佳答案

改变

来自

 ng-click="myFunction('Demsl{{question.id}}')"

ng-click="myFunction(question.id)"

关于javascript - 在 ng-click 函数中传递参数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42282668/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com