我有一个登录页面,如果用户已经登录则无法访问.因此登录页面会尝试将登录用户重定向回他们来自的页面.
如果用户单击链接转到页面,则重定向有效.问题是如果用户在About
页面中尝试通过url访问登录页面然后referrer agent
将不会设置,因此登录页面不会将用户重定向回About
页面,而是重定向回base url
(我使用codeigniter和ion auth库) .登录页面的重定向代码如下:
if($this->ion_auth->logged_in())
{
redirect($this->agent->referrer(), 'refresh');
}
Run Code Online (Sandbox Code Playgroud)
是否可以正确运行此代码并重定向,而不是始终重定向到基本URL?当用户登录时,我没有显示登录页面的链接.所以登录的用户只能使用url输入进入登录页面,我想要的是如果他们这样做,他们将被重定向回他们来自的页面.
我们需要exit;
在php中重定向之后做,因为exit;
不会阻止其余的代码运行.但是为什么我们不在javascript中做那样的事情.我想做点什么
if(window.location.replace("http://something.com")){
return;
}
Run Code Online (Sandbox Code Playgroud)
要么
window.location.replace("http://something.com");
throw "stop the execution.";
Run Code Online (Sandbox Code Playgroud)
我需要那样做吗?如果不是为什么?
这个代码是如何计算的?代码完全按照应有的方式工作,我只是没有得到逻辑.
<p>Select All :
<input type="checkbox" id="selectAll">
</p>
<p>
Item 1:
<input type="checkbox" class="children" value="item1">Item 2:
<input type="checkbox" class="children" value="item2">Item 3:
<input type="checkbox" class="children" value="item3">
</p>
Run Code Online (Sandbox Code Playgroud)
$(document).ready(function () {
$('#selectAll').click(function () {
$('.children').prop('checked', this.checked);
});
});
Run Code Online (Sandbox Code Playgroud)
让我们看一下下面的例子
int x[10];
cout<<x<<endl;
cout<<&x<<endl; //both couts are same.
int x;
cout<<x<<endl;
cout<<&x<<endl; //last two couts are different.
Run Code Online (Sandbox Code Playgroud)
这可能是什么原因?
<div id="feedback"></div>
<form id="myForm" action="controller.php" method="post">
location1: <input type="checkbox" name="location1" id="location1" value="location1"/>
location2: <input type="checkbox" name="location2" id="location2" value="location2"/><br>
<input type="submit" id="submit" value="Submit" />
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#submit').click(function(e){
var locations = [];
$('input:checkbox:checked').each(function(){
locations.push($(this).val());
});
locations.join(" ! ");
$('#feedback').text(locations);
e.preventDefault();
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,输出始终与逗号(,)分隔符一起使用.另外为什么$('#feedback').html(locations); 是不是在地点的元素之间进行任何分离?
我正在尝试创建一个询问用户输入的while循环.如果用户键入"hi",它将打印"hello",如果用户键入"done",它将结束循环,但如果用户键入任何其他内容或整数,则会显示"键入hi或done".代码如下:
public static void main(String[] args){
Scanner input = new Scanner(System.in);
while(!(input.nextLine()).equals("done")){
if((input.nextLine()).equals("hi"))
{
System.out.println("Hello");
}
else
{
System.out.println("Type hi or done");
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是使用此代码,它会在显示结果之前询问用户输入两次.有什么问题以及如何以最有效的方式处理它?
checkbox ×2
jquery ×2
redirect ×2
arrays ×1
c++ ×1
codeigniter ×1
exit ×1
http-referer ×1
ion-auth ×1
java ×1
javascript ×1
php ×1
reference ×1