`
huhu_long
  • 浏览: 69080 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

js timer

 
阅读更多
最近US那边问了个有关页面上button控制的问题。 如下:

引用
当某几个字段的值都不为空的时候显示button, 只要有一个部位空则隐藏之。


于是乎便有了如下代码:

<div style="height:0px;width:100%;">
    <script language="javascript">
        var targetElmt0 = document.getElementById('A0.R0.Estimated Close Date');
        var targetElmt1 = document.getElementById('A0.R0.Lead Source');
        var targetElmt2 = document.getElementById('A0.R0.Campaign Name');
        var targetElmt3 = document.getElementById('A0.R0.Industry Name - Translation');
        var targetElmt4 = document.getElementById('A0.R0.Annual Revenue');
		
        var targetValue0, targetValue1, targetValue2, targetValue3, targetValue4;
        if(targetElmt0 != null)
            targetValue0 = targetElmt0.innerHTML;
        if(targetElmt1 != null)
            targetValue1 = targetElmt1.innerHTML;
        if(targetElmt2 != null)
            targetValue2 = targetElmt2.innerHTML;
        if(targetElmt3 != null)
            targetValue3 = targetElmt3.innerHTML;
        if(targetElmt4 != null)
            targetValue4 = targetElmt4.innerHTML;
			
        if((targetValue0 == null || targetValue0 == '&nbsp;') || (targetValue1 == null || targetValue1 == '&nbsp;') ||
           (targetValue2 == null || targetValue2 == '&nbsp;') || (targetValue3 == null || targetValue3 == '&nbsp;') ||
           (targetValue4 == null || targetValue4 == '&nbsp;'))
            document.getElementById('BTN_TB_LeadDetailForm_ConvertLead').style.display = "none";
    </script>
</div>


US 看了说 "Very cool! It does work!", 但是他想在用户填完所有字段后又把那个button显示出来. 于是他的idea是加个web link 放到页面上, 默认是隐藏的, 然后想通过某中方法去判断是否该显示这个web link, 在然后用户可以点这个web link来刷新整个页面, 这是那个button就可以点了。。。。。。oh, my god!!!!!!!

有这么麻烦么??? 是不是一个timer就搞定了??? 有模有???
<div style="height:0px;width:100%;">
    <script language="javascript">
	    var allFilled = checkIfAllFilled();
		if(!allFilled) hide();
		
		var intervalID = setInterval("show()", 1000);
	
	    function checkIfAllFilled() {
			var targetElmt0 = document.getElementById('A0.R0.Estimated Close Date');
			var targetElmt1 = document.getElementById('A0.R0.Lead Source');
			var targetElmt2 = document.getElementById('A0.R0.Campaign Name');
			var targetElmt3 = document.getElementById('A0.R0.Industry Name - Translation');
			var targetElmt4 = document.getElementById('A0.R0.Annual Revenue');
			
			var targetValue0, targetValue1, targetValue2, targetValue3, targetValue4;
			if(targetElmt0 != null)
				targetValue0 = targetElmt0.innerHTML;
			if(targetElmt1 != null)
				targetValue1 = targetElmt1.innerHTML;
			if(targetElmt2 != null)
				targetValue2 = targetElmt2.innerHTML;
			if(targetElmt3 != null)
				targetValue3 = targetElmt3.innerHTML;
			if(targetElmt4 != null)
				targetValue4 = targetElmt4.innerHTML;
				
			if((targetValue0 == null || targetValue0 == '&nbsp;') || (targetValue1 == null || targetValue1 == '&nbsp;') ||
			   (targetValue2 == null || targetValue2 == '&nbsp;') || (targetValue3 == null || targetValue3 == '&nbsp;') ||
			   (targetValue4 == null || targetValue4 == '&nbsp;'))
			   return false;
			   
			return true;
		 }
		 
		 function hide() {
            document.getElementById('BTN_TB_LeadDetailForm_ConvertLead').style.display = "none";
		 }
		
		function show() {
			if(checkIfAllFilled()) {
				document.getElementById('BTN_TB_LeadDetailForm_ConvertLead').style.display = "block";
				clearInterval(intervalID);
			}
		}
    </script>
</div>


。。。。。。。。。 我是分割点 。。。。。。。。。。。。

老外就是这样, 一次不把需求说清楚, 本来自己也是想到了但怕画蛇添足所以就没加:
如果所有字段都填好的, 但现在null out任意一个, 则需要隐藏那个button.

简单是简单, 不过来回折腾了好几封邮件。。。恩就把show()方法改一下就好了
function show() {
			if(checkIfAllFilled()) {
				document.getElementById('BTN_TB_LeadDetailForm_ConvertLead').style.display = "block";
			} else {
				document.getElementById('BTN_TB_LeadDetailForm_ConvertLead').style.display = "none";
			}
		}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics