2012-07-30 220 views
0

我面临的问题是我的调查中有一系列问题。第一个问题要求用户点击复选框,如果他不是成员。如果用户选中复选框,则光标应该自动滚动到页面的底部,跳过所有后面的问题。滚动到页面底部

我已经尝试过使用jquery的不同功能,但都没有工作。 这是我以前试过(P.S也没有这项工作)的代码

<?php 
    if(!stristr($_SERVER['PHP_SELF'],"printSummary")) { 
     require_once("../lib/include/common.inc.php"); 
    } else { 
     require_once("../../lib/include/common.inc.php"); 
    } 
    ob_start(); 

    $node_id = $parentnode?$parentnode:getDataFromSession("data,node_id"); 
    $node_name = get_node_name($node_id,$_SESSION["survey"],$_SESSION['idLink']); 
    $surveyForText = getText2("This survey is for:")." ".$node_name; 

    if(strlen($node_name)>0) { 
     echo "<script type='text/javascript'>"; 
     echo "$(document).ready(function(){"; 
     echo "$('.generalErrorMsg').first().addClass('generalErrorMsgWithMargin').text(\"$surveyForText\");"; 
     echo "});"; 
     echo "</script>"; 
    } 
//code that I am talking about starts here 
    $currentPageNum = currentPageNumber(); 
    if($currentPageNum==4) 
    { 
     echo "<script type=\"text/javascript\"> 
     $(document).ready(function(){ 
      $('input[type=checkbox]').click(function() { 
       alert('here'); 
       setTimeout(function() { 
        window.scrollTo(0, 1) },100); 
      }); 


      //window.scrollBy(100,100); // horizontal and vertical scroll increments 
      //scrolldelay = setTimeout('pageScroll()',80); // scrolls every 80 milliseconds 
     });"; 
     echo "</script>"; 
    } 
    ?> 

请帮我解决代码。在此先感谢 -Jathin

回答

0

你应该尝试

scrollTop. 

scrollTopDOM Object属性。

但在jQuery中有一个函数scrollTop(),所以你可以在jQuery中使用。

$(window).scrollTop(100);

$('input[type=checkbox]').click(function() { 
    alert('here'); 
    setTimeout(function() { 
     window.scrollTo(0, 1) },100); 
}); 

变化

$('input[type=checkbox]').click(function() { 
    //alert('here'); 
    setTimeout(function() { 
     $(window).scrollTop(100);},100); 
}); 

,如果你有一个元素,其中滚动 你可以

$(window.)scrollTop($('#elemenet-id').offset().top); 
+0

我应该只添加这行代码? – Jathin 2012-07-30 11:57:50

+0

检查更新的答案。 – 2012-07-30 12:02:16

+0

让我检查一下。给我一分钟 – Jathin 2012-07-30 12:06:15

0

代码尝试是很难,因为阅读的PHP,HTML和JavaScript的混合物 你最好只显示最终的html + javascript。 无论如何,如果你需要滚动窗口到文档的页脚 - $(document).scrollTop($(document).height())