不断刷新jquery数据 [英] refresh jquery data constantly
问题描述
我有这段代码
<script type="text/javascript">
var scheduled = $("select").filter(function() {
return $(this).val() == "<%=pempidw%>";
});
document.write(scheduled.length);
</script>
它正在计算选择某个项目的次数。但是,如果我在更改选项后刷新页面,它只能正常工作并且计数正确。我需要一种方法来不断刷新或实时,所以如果它是每秒自动刷新,每次在页面中更改它将正确反映。
and it is working with counting the amount of times a certain item is selected. however, it only works and counts properly if i refresh the page after options are changed. i need a way for this to constantly refresh or be "live" so if it was to auto refresh every second, everytime something is changed in the page it would reflect correctly.
我知道怎样做一整页autorefresh而不是我不想那样。
I know how to do a full page autorefresh and no I don't want that.
推荐答案
我不确定我理解..如果您只是想在点击某些内容时更新(写入),那么为什么不移动写入:
I'm not sure I understand.. if you just want the count to update (write) whenever something is clicked, why don't you just move the write:
$(".<%=pempidw%>-element").on('click', function () {
<%=pempidw%>Count++;
document.write(<%=pempidw%>Count);
});
您也可以将功能更改为使用更改而不是on。
also you may want to change the function to use change instead of on.
这篇关于不断刷新jquery数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!