简体   繁体   English

使用javascript中的onclick获取输入标签中每个值的值

[英]Get the value of each value in input tag using onclick in javascript

I have a loop of button and input tags 我有一个循环的按钮和输入标签

    while($row = mysqli_fetch_array($notifqry))
    {
        extract($row);
        if($type_of_notif == '1')
        {
        echo '<button class="dropdown-item"  onclick="notifview()">New Announcement!</button>';
        echo '<input type="text" id="notifid" name="notifid" value="'.$notifid.'">';

        }
    }

按钮/链接

and in my javascript 在我的javascript中

function notifview() {
var notifid = $('#notifid').val();
alert(notifid);
}

however, if I click the different button/links I only get the first row id only like this even i click the button w/ value of 3 or 4 但是,如果我单击不同的按钮/链接,即使我单击值3或4的按钮,也只能得到这样的第一行ID

在此处输入图片说明

id 's need to unique for every input field. id对于每个输入字段都需要唯一。 Also, if multiple input fields are created dynamically you will need to use event delegation to determine which button was clicked and then correspondingly extract that value. 另外,如果动态创建了多个输入字段,则需要使用event delegation来确定单击了哪个按钮,然后相应地提取该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM