為什么我改成別的網(wǎng)址,卻還是顯示慕課的網(wǎng)頁啊,我瀏覽器的問題?
? ? function openWindow()
? ? {
? ? ? ? var str=confirm("是否打開?");
? ? ? ? if(str){
? ? ? ? ? ? var str1=prompt("請輸入網(wǎng)址:","http://idcbgp.cn/")
? ? ? ? ? ? if(str1){
? ? ? ? ? ? window.open('str1','_blank','width=400,height=500,menubar=no,toolbar=no');
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? }?
2016-03-26
你的str1在if語句中沒有給判斷條件。
? 對于if來說,只要你點了確定,它就會默認去執(zhí)行,而不會進行判斷。
如果你改成if(str1==1),此時點了確定后,if會判斷你輸入的值是不是1,如果是1,就會繼續(xù)執(zhí)行if語句,也就是打開慕課網(wǎng)。如果不是1,那機會執(zhí)行else語句。
2016-03-26
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> ??
? <script type="text/javascript"> ?
? ? ? function openWindow(){
? ? ? ? var ?boolean1 = confirm("是否打開新網(wǎng)站");
? ? ? ? if (boolean1==true) {
? ? ? ? ? var string1 = prompt("請您輸入要打開的網(wǎng)站","http://idcbgp.cn");
? ? ? ? ? var string2 = "http://";
? ? ? ? ? var string3 = string1.contains(string2);
? ? ? ? ? ? if (string3==true) {
? ? ? ? ? ? ? window.open(string1);
? ? ? ? ? ? }else{
? ? ? ? ? ? ? window.open("http://"+string1);
? ? ? ? ? ? }
? ? ? ? ??
? ? ? ? }
? ? ? }
? ??
? </script>?
?</head>?
?<body>?
? ? ? <input type="button" value="新窗口打開網(wǎng)站" onclick="openWindow()" />?
?</body>
</html>
2016-03-26
應該寫成這樣
2016-03-26
我細細研究了下,我的調(diào)試成功了,你的我也幫你修改了下(僅供參考)
? ?function openWindow()
? ? {
? ? ? ? var str=confirm("是否打開?");
? ? ? ? if(str==true){
? ? ? ? ? ? var str1=prompt("請輸入網(wǎng)址:","http://idcbgp.cn/")
? ? ? ? ? ?window.open(str1,['_blank'],['width=400','height=500','menubar=no','toolbar=no']);
? ? ? ? }
? ? ? ? else{
? ? ? ? }
? ? ? ? }?
? ? //打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
2016-03-26
同問,請問你這個問題的原因找到?jīng)]?
2016-03-26
加不加好像效果都一樣,輸入其它網(wǎng)址時為啥還是打開imooc的網(wǎng)站呀,prompt(str1,str2),str2的值沒有被改變?
2016-03-25
open里面,str1就是網(wǎng)址了,不用加單引號