JS

1.js獲取input框的值:

html:

<input type="text" id="a" />

js:

var a = document.getElementById("a").value;

2.js獲取文字的值

html:

<div id="hao">你好</div>

js:

var hao =?document.getElementById("hao").innerHTML;

3.js獲取select下拉框的值:

html:

<select id="test" name="">

<option value="ha">哈哈</option>

<option value="xi">嘻嘻</option>

</select>

js:

var myselect = document.getElementById("test");

var index=myselect.selectedIndex ;

var value = myselect.options[index].value;

外加:

獲取select下拉框種更多的值

4.JS修改display屬性:

普遍方法:

$("#id").css('display','none'); //隱藏

$("#id").css('display', 'block'); //顯示

上述方法在ie6、搜狗和360等瀏覽器中不支持。

通用方法:

$("#id").hide(); //隱藏

$("#id").show(); //顯示

在各瀏覽器中通用,應(yīng)該是使用了JQuery封裝函數(shù)hide(),show()的緣故,對(duì)各個(gè)瀏覽器的判斷由JQuery完成。

5.JS給img的src賦值:

用js原生方法:document.getElementById("#id").src = "xxxx.jpg";

用Jquery方法:$("#id").attr("src","xxxx.jpg");

$("#id").src = "xxxx.jpg";

document.getElementById("#id").attr("src","xxxx.jpg");

原文地址:https://www.cnblogs.com/ziyoublog/p/9138003.html。

任何形式的轉(zhuǎn)載都請(qǐng)注明出處!

6.JS清空文本框

document.getElementById("#id").value="";

7.監(jiān)聽input框的變化

html內(nèi)容:

<input type="text" class="styled" name="user" id="user" oninput="zhang()">

<p style="color: red;display: none;" id="uuu">123</p>

js內(nèi)容:

js通過oninput方法監(jiān)聽id為user的input框,發(fā)生改變時(shí)驗(yàn)證一次js,如果后臺(tái)有同樣的數(shù)據(jù),那么p標(biāo)簽的內(nèi)容就會(huì)變?yōu)椤?b>您輸入的賬號(hào)已被注冊(cè),請(qǐng)重新輸入!”,而且還會(huì)將display:block傳給p標(biāo)簽,這樣就會(huì)顯示了。否則的話還是正常none隱藏。

8.跳轉(zhuǎn)

當(dāng)前頁面跳轉(zhuǎn):

window.location.href="";

打開新窗口跳轉(zhuǎn):

window.open("");

父級(jí)頁面跳轉(zhuǎn):

parent.location.href="";

頂級(jí)頁面跳轉(zhuǎn):

top.location.href="";

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容