點(diǎn)擊怎么沒(méi)反應(yīng)
!--當(dāng)點(diǎn)擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->
? ? <input type="button" value="改變顏色" onclick="color()"> ?
? ? <input type="button" value="改變寬高" onclick="top()">
? ? <input type="button" value="隱藏內(nèi)容" onclick="display()">
? ? <input type="button" value="顯示內(nèi)容" >
? ? <input type="button" value="取消設(shè)置" >
? </form>
? <script type="text/javascript">
?var mychar=document.getElementById("con");
? var txtchar=document.getElementById("txt");
//定義"改變顏色"的函數(shù)
function color()
{
? ? mychar.style.color="red";
? ? txtchar.style.backgroundColor="#D1BDA1";
}
function top() {
? ? txtchar.style.width="200px";
? ? txtchar.style.heigth="200px";
}
function display()
{
?txtchar.style.display="none";
}
2016-07-28
應(yīng)該是 onClick="" 那里的c沒(méi)大寫(xiě)
2016-08-01
function ?我換了個(gè)函數(shù)名就可以了 不知道是不是用了關(guān)鍵字命名函數(shù)
2016-07-28
不對(duì)喲。我用你這個(gè)代碼跑的動(dòng)呢。你可能哪里出問(wèn)題吧,那些標(biāo)簽有對(duì)應(yīng)嗎?這些代碼內(nèi)容基本沒(méi)啥問(wèn)題。另onclick剛查了和測(cè)試一下也沒(méi)區(qū)分大小寫(xiě)。。
2016-07-28
<form>
<input type="text" id="con" value="Test"></input>
<input type="text" id="txt" value="Test"></input>
? ?<input type="button" value="改變顏色" onclick="color()"> ?
? ? <input type="button" value="改變寬高" onclick="top()">
? ? <input type="button" value="隱藏內(nèi)容" onclick="display()">
? ? <input type="button" value="顯示內(nèi)容" >
? ? <input type="button" value="取消設(shè)置" >
? </form>
? <script type="text/javascript">
?var mychar=document.getElementById("con");
? var txtchar=document.getElementById("txt");
//定義"改變顏色"的函數(shù)
function color()
{
? ? mychar.style.color="red";
? ? txtchar.style.backgroundColor="#D1BDA1";
}
function top() {
? ? txtchar.style.width="200px";
? ? txtchar.style.heigth="200px";
}
function display()
{
?txtchar.style.display="none";
}
</script>
以上是我測(cè)試代碼,可用。
你的代碼少了個(gè)<from>開(kāi)頭,以及你的代碼少了個(gè)</script>結(jié)束
2016-07-27
onClick C大寫(xiě)