"> 会给我类似的东西: View Detail View De-6ren">
gpt4 book ai didi

php - 如何从生成的文本输入中获取值?

转载 作者:行者123 更新时间:2023-12-01 02:34:40 25 4
gpt4 key购买 nike

我正在 foreach 循环中创建一些输入字段:

<?php foreach($this->results as $value){?>
<td><a href="$" class="buttonDetails">View Detail</a>
<input name="processor" id="processor" type="text" value="<?php echo $value['processor']; ?>">
<input name="auth_code" class="auth_code" type="hidden" value="<?php echo $value['auth_code']; ?>"></td>
<? } ?>

会给我类似的东西:

<td>
<a href="$" class="buttonDetails">View Detail</a>
<input name="processor" class="processor" type="text" value="19">
<input name="auth_code" class="auth_code" type="text" value="4">
</td>
<td>
<a href="$" class="buttonDetails">View Detail</a>
<input name="processor" class="processor" type="text" value="9">
<input name="auth_code" class="auth_code" type="text" value="11">
</td>
...

然后我尝试获取值:

$('.buttonDetails').live("click", function (){
var processor = $('.processor').val();
alert(processor);

$.ajax({
type: 'POST',
dataType: 'json',
url: '/decline/list',
async: false,
data: {
processor: processor,
processor: auth_code
},
success: function(json) {
$('#details').html(json.processor);
}
});
return false;
});

我遇到的问题是,当我单击任何链接时,我的警报会获得相同的数字(通常是第一个输入的第一个值)。

有什么想法可以解决这个问题吗?我尝试过用 id 替换类,用“live”替换“click”,但仍然没有效果

编辑:

我相信我需要区分类别,以便他链接知道要提取什么值..??

编辑:如果我也想获取“auth_code”怎么办?

最佳答案

尝试:

$('.buttonDetails').live("click", function (){
var processor = $(this).next(".processor").val();
alert(processor);
/* snip */
});

使用next获取被单击的链接旁边的输入。

<小时/>

更新(由于评论)。

您可以使用 nextAll 类似地找到 auth_code相反:

var auth_code = $(this).nextAll(".auth_code").val();

此外,您确定为 AJAX 调用提供了正确的值吗?您似乎指定了 processor 两次。为处理器指定的第一个值将被覆盖。

关于php - 如何从生成的文本输入中获取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8360439/

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