如何在同一页面中为 Javascript 提供 ID 值。
示例数据:
<a href="" id="ctextarea<?php echo $uid; ?>"/>
JS:
function recountss()
{
var maxlen=280;
var current = maxlen-$('#ctextarea').val().length;
$('.counters').html(current);
if(current<0 || current==maxlen)
{
$('.counters').css('color','#D40D12');
$('input.comment_button').attr('disabled','disabled').addClass('inact');
}
else if (!$.trim($("#ctextarea").val())) {
$('input.comment_button').attr('disabled','disabled').addClass('inact');
}
else
$('input.comment_button').removeAttr('disabled').removeClass('inact');
if(current<10)
$('.counters').css('color','#D40D12');
else if(current<20)
$('.counters').css('color','#5C0002');
else
$('.counters').css('color','#C0C0C0');
}
我尝试使用 get class,但它只对 1 个数据有效,对许多数据无效。 有想法吗?
谢谢。
最佳答案
这应该有效:
<script type="text/javascript">
var id = "ctextarea<?php echo $uid; ?>";
</script>
在你的 javascript 中,你可以这样做:
var current = maxlen-$(id).val().length;
但是您应该为您的变量使用其他名称。
关于php - 在同一页面中将 PHP 值赋予 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13513545/