Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.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_Php_Html_Arrays - Fatal编程技术网

Javascript 如何使用按钮从文本区域数组中获取数据

Javascript 如何使用按钮从文本区域数组中获取数据,javascript,php,html,arrays,Javascript,Php,Html,Arrays,从textarea按钮对的动态数组中提取文本时出现问题。数组中的每个按钮总是指向第一个文本区域 这是我的代码片段 //提交调查结果 $(“#表”)。在('click','input#accept',function()上{ var id=$('textarea#').val(); 警报(id); }) //... 看看你生成的JS。上面写着$('textarea#')。它似乎错过了id本身 作为您所做操作的替代方法:我将通过查找与单击的按钮位于同一tr中的文本区域来完成此操作。大概是这样的:

从textarea按钮对的动态数组中提取文本时出现问题。数组中的每个按钮总是指向第一个文本区域

这是我的代码片段

//提交调查结果
$(“#表”)。在('click','input#accept',function()上{
var id=$('textarea#').val();
警报(id);
})

//...

看看你生成的JS。上面写着
$('textarea#')
。它似乎错过了id本身

作为您所做操作的替代方法:我将通过查找与单击的按钮位于同一
tr
中的文本区域来完成此操作。大概是这样的:

JS

演示HTML

<table id="table">
    <tr>
        <td colspan="4">
            <textarea id="finding" style="resize:none;" class="form-control" name="finding" cols="30" data-id="335" rows="3"></textarea>
        </td>
        <td colspan="1">
            <input id="accept" data-id="335" type="button" class="btn btn-success" value="re-submit"/>
            <input id="reject" data-id="335" type="button" class="btn btn-danger" onclick="confirm('are you sure you want to reject this prescription?')" value="reject"/>
        </td>
    </tr>
    <tr>
        <td colspan="4">
            <textarea id="finding" style="resize:none;" class="form-control" name="finding" cols="30" data-id="335" rows="3"></textarea>
        </td>
        <td colspan="1">
            <input id="accept" data-id="335" type="button" class="btn btn-success" value="re-submit"/>
            <input id="reject" data-id="335" type="button" class="btn btn-danger" onclick="confirm('are you sure you want to reject this prescription?')" value="reject"/>
        </td>
    </tr>
</table>


请参阅工作演示:

能否添加PHP生成的javascript和html?
输入#接受“
仅显示附加到
单击
事件的元素?
php
是否为所有
input
元素设置重复的
id
\accept
?这是javascript
$('table')。在('click','input#accept',function(){var id=$('textarea#').val();alert(id)}
这是html
@guest271314否,我为每一行设置了一个唯一的id。我似乎也注意到了这一点。如何获取文本区域的id。每当我链接id时,它总是漏掉它。看看我修改过的答案。它向您展示了一种无需ID即可完成此操作的方法
<table id="table">
    <tr>
        <td colspan="4">
            <textarea id="finding" style="resize:none;" class="form-control" name="finding" cols="30" data-id="335" rows="3"></textarea>
        </td>
        <td colspan="1">
            <input id="accept" data-id="335" type="button" class="btn btn-success" value="re-submit"/>
            <input id="reject" data-id="335" type="button" class="btn btn-danger" onclick="confirm('are you sure you want to reject this prescription?')" value="reject"/>
        </td>
    </tr>
    <tr>
        <td colspan="4">
            <textarea id="finding" style="resize:none;" class="form-control" name="finding" cols="30" data-id="335" rows="3"></textarea>
        </td>
        <td colspan="1">
            <input id="accept" data-id="335" type="button" class="btn btn-success" value="re-submit"/>
            <input id="reject" data-id="335" type="button" class="btn btn-danger" onclick="confirm('are you sure you want to reject this prescription?')" value="reject"/>
        </td>
    </tr>
</table>