我想要获得div类“nameregion”的值,我必须通过POST在Ajax中发送它。 我有一个foreach,这是我的尝试,但它不工作,我收到一个空白regionid。切换foreach获取div类的价值
谢谢。
foreach($data as $plus) {
if($prev_type != $plus['FRN_TYPE_ENTREE_VALUE']) {
$prev_type = $plus['FRN_TYPE_ENTREE_VALUE'];
echo ' <div style="color: #708090; font-size: 24px; margin-bottom: 30px; margin-left: 20px; margin-top: 25px; text-align: left;">
'.$plus['FRN_TYPE_ENTREE_VALUE'].'</div>';
}
echo '<a href="#" class="region" value="'.$plus['FRN_TYPE_ENTREE'].'"><img src="images/plus.png" style="float: left; margin-top:-5px; margin-left: 15px; margin-right: 5px;"></a>
<div style="color: #000; font-size: 20px; margin-bottom: 30px; margin-left: 20px; margin-top: 0px; text-align: left;" class="nameregion" value="oui">'.$plus['FRN_RGN_VALUE'].'</div></a>
<div class="mytoggle"><div class="val"></div></div>';
}
<script type="text/javascript">
$(".mytoggle").hide();
$('.region').click(function(){
$(this).next().next('.mytoggle').toggle('fast');
var catalogue = "catalogue";
var regionid = $(this).next().val();
$.ajax({
type: 'POST',
url: 'function.php',
data: {'catalogue': catalogue, 'regionid': regionid },
success: function (data) {
$(".val").append(""+data+"").fadeIn(1000);
}
});
$(".val").empty();
return false; //to avoid the link from working
});
</script>
我想要得到的值 “OUI” 在这里:
<div style="color: #000; font-size: 20px; margin-bottom: 30px; margin-left: 20px; margin-top: 0px; text-align: left;" class="nameregion" value="oui">'.$plus['FRN_RGN_VALUE'].'</div></a>
感谢。
如果我这样做我得到 '$加[ 'FRN_RGN_VALUE'。',我想 “OUI”。我会为每个foreach放置不同的数据值 – user3162341
div元素没有值属性请参阅我的更新请@ user3162341 –
完美,这是我想要的,数据值解决了我的问题,谢谢 – user3162341