0
任何上级可以帮助我解决下面的问题。我的脚本错了。
我的问题是,我如何从循环内部获得一个值,当循环内部还有一个按钮和按钮时。 非常感谢我如何定义哪个按钮从一个循环内点击即可
$(document).ready(function(){
var btn = document.getElementsByid("button");
for (var i = 0; i < document.getElementsByid("button").length; i++) {
/* my problem in here. How I define which one of the button
onclick then get value from the <input type=""hidden"> */
btn[i].onclick = function() {
var hd1 = $("#hidden1"+i).val();
$.get('try.php', {
sendResult: hd1
}, function(data) {
$('#returnResult').html(data);
});
};
};
});
<!-- I want sending one of the value from '$arrayValue'. -->
<?php
$arrayValue = array(a, b, c);
foreach($arrayValue as $eachResult) {
echo '
<input type="hidden" id="hidden1" value="'.$eachResult["arrayValue"].'">
<button type="button" id="button"></button>
';}
?>
非常感谢回答我的问题,但仍然无法为我的剧本工作。我更改为使用类并使用getElementFromClassName,但仍然只能从循环中获取最后一个值。谢谢 – Fun