Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未在其中一个附加文本区域中添加内容_Javascript_Jquery - Fatal编程技术网

Javascript 未在其中一个附加文本区域中添加内容

Javascript 未在其中一个附加文本区域中添加内容,javascript,jquery,Javascript,Jquery,我在下面有一个函数,当单击“添加”按钮将内容添加到单个文本区域时,if语句在该函数中起作用: 下面是单个文本区域及其加号按钮的代码: <form id="QandA" action="<?php echo htmlentities($action); ?>" method="post"> <div id="detailsBlock"> <table id="question"> <tr> <td rowspan="3"&

我在下面有一个函数,当单击“添加”按钮将内容添加到单个文本区域时,if语句在该函数中起作用:

下面是单个文本区域及其加号按钮的代码:

<form id="QandA" action="<?php echo htmlentities($action); ?>" method="post">

<div id="detailsBlock">
<table id="question">
<tr>
    <td rowspan="3">Question:</td> 
    <td rowspan="3">
        <textarea class="questionTextArea" id="mainTextarea" rows="5" cols="40" name="questionText"></textarea>
    </td>
</tr>
</table>

<table id="plus" align="center">
<tr>
<th>
<a onclick="return plusbutton();">
<img src="Images/plussign.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage" id="mainPlusbutton" name="plusbuttonrow"/>
</a>
<span id="plussignmsg">(Click Plus Sign to look <br/> up Previous Questions)</span>
</th>
</tr>
</table>
</div>
</form>

您没有传递
plusbutton()
函数期望作为参数的元素,这就是函数无法找到同级元素以获取其内容的原因。尝试:

<a onclick='return plusbutton(this);'>


至少你现在正在尝试编写代码,而不是重复同样的问题。。你有没有像我之前提出的几个问题那样尝试用
替换
?您已经将带有
live()
的事件委派绑定到那些将元素作为参数传递给
plusbutton()
函数的图像上,而
a
onclick
没有。您的意思是,您想要附加文本,而不是替换它吗?@ParthThakkar我的意思是实际替换文本。因此,让我们假设附加行中的文本区域saud“What is 2+2?”,但是我想通过选择诸如“What is 45+45?”(什么是45+45?”)之类的问题来更改该问题,然后它应该将中的“What is 2+2?”替换为“What is 45+45?”textarea@FabrMattícioé我按你说的做了但没用,当我删除onclick并用href='#'更改它时,它不会打开模式窗口。这是因为在live函数中它是
$('.plusimage')。每个(function(){
),而每个附加的textarea的类是.imageplus吗?你能把它弄出来吗?你知道这确实是一段很长的代码,所以fiddle会有所帮助。
    var plusbutton_clicked;

 function insertQuestion(form) {


var $tbody = $('#qandatbl > tbody'); 
var $tr = $("<tr class='optionAndAnswer' align='center'></tr>");
var $plusrow = $("<td class='plusrow'></td>");
var $question = $("<td class='question'></td>");


 $('.questionTextArea').each( function() {

 var $this = $(this);
var $questionText = $("<textarea class='textAreaQuestion'></textarea>").attr('name',$this.attr('name')+"[]")
.attr('value',$this.val());

 $question.append($questionText);

});

 $('.plusimage').each( function() {

var $this = $(this);
var $plusimagerow = $("<a onclick='return plusbutton();'><img src='Images/plussign.jpg' width='30' height='30' alt='Look Up Previous Question' class='imageplus'/></a>").attr('name',$this.attr('name')+"[]")
.attr('value',$this.val());

$plusrow.append($plusimagerow);

 });

$tr.append($plusrow);
$tr.append($question);
$tbody.append($tr);                     

}
<a onclick='return plusbutton(this);'>