導航:首頁 > 編程語言 > jsvalueundefined

jsvalueundefined

發布時間:2021-10-24 14:54:33

javascript 為什麼彈出的是 undefined

//唯一會出現undefined的情況是,你在呼叫save這個方法時沒有傳入value
//造成load在取值時出現undefined
下面例子
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function save(value) {
var Days = 30;
var exp = new Date();
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
document.cookie = "savetThing" + "=" + encodeURI(value) + ";expires=" + exp.toGMTString();
}

function load() {
var cookies = document.cookie.split(";");
for( var i = 0; i < cookies.length ; i ++){
var cookieCrumbs = cookies[i].split("=");
var cookieName = cookieCrumbs[0];
var cookieValue = cookieCrumbs[1];
if( cookieName == "savetThing"){
document.getElementById("content").value=decodeURI(cookieValue);
}
}
}

function DelCookie() {
document.cookie = "savetThing"+"=;expires="+(new Date(0)).toGMTString();
reLoad();
}

function reLoad() { window.location.reload(); }
</script>
</head>
<body>
<input type="text" id="content" value="" style="width:300px;">
<input type="button" id="btn1" value="save" onclick="save('這是測試');">
<input type="button" id="btn2" value="load" onclick="load();">
<input type="button" id="btn3" value="del" onclick="DelCookie();">
</body>
</html>

② 下面js語句有什麼錯誤取出value值為undefined

eval("("+s+")");

③ js創建節點後取值找不到該元素 為undefined

js添加的頁面元素,通過查看頁面源代碼是看不到的,可以通過js來的到創建的元素 .還可以通過火狐的debug看到

④ JS為什麼出現undefined

//依你的代碼寫的測試是可以正常運作的,
//唯一會出現undefined的情況是,你在呼叫save這個方法時沒有傳入value
//造成load在取值時出現undefined

<html>
<head>
<title>Test</title>
<scripttype="text/javascript">
functionsave(value){
varDays=30;
varexp=newDate();
exp.setTime(exp.getTime()+Days*24*60*60*1000);
document.cookie="savetThing"+"="+encodeURI(value)+";expires="+exp.toGMTString();
}

functionload(){
varcookies=document.cookie.split(";");
for(vari=0;i<cookies.length;i++){
varcookieCrumbs=cookies[i].split("=");
varcookieName=cookieCrumbs[0];
varcookieValue=cookieCrumbs[1];
if(cookieName=="savetThing"){
document.getElementById("content").value=decodeURI(cookieValue);
}
}
}

functionDelCookie(){
document.cookie="savetThing"+"=;expires="+(newDate(0)).toGMTString();
reLoad();
}

functionreLoad(){window.location.reload();}
</script>
</head>
<body>
<inputtype="text"id="content"value=""style="width:300px;">
<inputtype="button"id="btn1"value="save"onclick="save('這是測試');">
<inputtype="button"id="btn2"value="load"onclick="load();">
<inputtype="button"id="btn3"value="del"onclick="DelCookie();">
</body>
</html>

⑤ js怎麼取得值是undefined

對象的屬性沒有定義(或不應該有這個屬性),就會報這個,不是value的問題專
<td id="myid"></td>
如alert(document.getElementById("myid").value),就會是undefined。因為td就沒有屬value這個屬性

閱讀全文

與jsvalueundefined相關的資料

熱點內容
linux目錄中創建文件夾許可權設置密碼 瀏覽:759
word文檔正式文件模版 瀏覽:247
linux文件系統的類型是 瀏覽:111
蘋果的無線傳輸文件找不到了 瀏覽:102
密件文件名能出現在通知嗎 瀏覽:832
編寫一個web應用程序 瀏覽:350
哪些場所網路好 瀏覽:171
華為手機怎麼找到以前安裝過的app 瀏覽:100
49塊一單約人陪的app是什麼 瀏覽:570
ug文件格式圖片 瀏覽:24
興趣班編程課是學什麼 瀏覽:879
怎麼才能加微信醫葯群 瀏覽:601
微信表情小蘿莉親吻 瀏覽:876
我國應如何做好互聯網網路空間的治理工作 瀏覽:777
今日最新聞投票app 瀏覽:53
aecs6卸載工具 瀏覽:645
視頻文件包含的信息 瀏覽:238
湖北可編程晶振參數有哪些 瀏覽:485
在美國買蘋果7那個版本的 瀏覽:557
網路營銷文檔 瀏覽:204

友情鏈接