gpt4 book ai didi

javascript - prev() 似乎不起作用

转载 作者:行者123 更新时间:2023-11-30 10:24:00 27 4
gpt4 key购买 nike

我在一个文件中有这样的代码...

      $d = new db();
class db
{
function fetchform()
{
global $wpdb;
$content='';
$result = $wpdb->get_results("select * from kp_contact_form",ARRAY_A);
$path =plugins_url().'/kp_contactus/ajax.php';
$content.='<form action="'.$path.'" method="POST">';
$content.= '<table><span id="error"></span>';
foreach ($result as $row )
{
$content.='<tr><td><label>'.$row['label'].'</label> </td>
<td><input type="'.$row['type'].'" name="'.$row['name'].'" required> </td>
<td><a href="#" id="'.$row['fid'].'" class="remove">Remove</a></td>';
}
echo $content;
}
}

我在这里打印上面的函数数据

 <div id="showform" style="margin-top: -100px">
<?php $d->fetchform(); ?>
</div>

现在我正在尝试获取 input typename 属性

 $(".remove").click(function(){
alert("hii");
var fid=$(this).prev().attr('name');
alert(fid); // giving undefined
}

当我执行alert时,我得到了undefined...我不知道我的代码出了什么问题..

谁能帮帮我

提前致谢

最佳答案

.remove 的前一个元素是……什么都没有!这是因为 .removetd 中的第一个元素。您需要获取父元素、它的前一个兄弟元素,最后是 input 元素:

var fid = $(this).parent().prev().find("input").attr('name');

关于javascript - prev() 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20400218/

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