有誰(shuí)幫我看看哪里出錯(cuò)了,為什么點(diǎn)擊按鈕沒(méi)有反映呢?
? <!--當(dāng)點(diǎn)擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->
??? <input type="button" value="改變顏色"? onclick="changeColor()">?
??? <input type="button" value="改變寬高"? onclick="changeWidth()">
??? <input type="button" value="隱藏內(nèi)容"? onclick="changeHidden()">
??? <input type="button" value="顯示內(nèi)容"? onclick="changeDisplay()">
??? <input type="button" value="取消設(shè)置"? onclick="changeSet()">
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數(shù)
function changeColor(){
??? var obj=document.getElementById("txt");
??? obj.style.color="red";
??? obj.style.backgroundColor="#ccc";
}
//定義"改變寬高"的函數(shù)
function changeWidth(){
??? var obj=document.getElementById("txt");
??? obj.style.width="200px";
??? obj.style.height="300px";
}
//定義"隱藏內(nèi)容"的函數(shù)
function changeHidden(){
??? var obj=document.getElementById("txt");
??? obj.style.display="none";
}
//定義"顯示內(nèi)容"的函數(shù)
function changeDisplay(){
??? var obj=document.getElementById("txt");
??? obj.style.display="block";
}
//定義"取消設(shè)置"的函數(shù)
function changeSet(){
??? var obj=document.getElementById("txt");
??? var con=confirm("是否確定取消設(shè)置");
??? if(con==true){
??????? obj.removeAttribute('style');
??? }else{
?????? document.write("您取消了設(shè)置"); |
?? }
}
2016-12-02
各位小伙伴,我終于找到錯(cuò)誤所在了,是最后一個(gè)大括號(hào)打成了中文下的,已經(jīng)找到并解決了,初學(xué)者還是得注意這一點(diǎn)。
2016-12-02
在瀏覽器按F12看哪里錯(cuò)了 。。不過(guò)我想問(wèn)定義這么多obj可不可以(也是菜鳥(niǎo))
2016-12-01
---------------------------------
沒(méi)看出你錯(cuò)哪兒了,你參考下我的
2016-11-30
樓主方法沒(méi)錯(cuò)啊
2016-11-30
?? <input type="button" value="改變顏色" ?onclick="changeColor()"> ?
? ? <input type="button" value="改變寬高" ?onclick="changeWidth()">
? ? <input type="button" value="隱藏內(nèi)容" ?onclick="changeHidden()">
? ? <input type="button" value="顯示內(nèi)容" ?onclick="changeDisplay()">
? ? <input type="button" value="取消設(shè)置" ?onclick="changeSet()">
?
? <script type="text/javascript">
//定義"改變顏色"的函數(shù)
var obj=document.getElementById("txt");
function changeColor(){
? ??
? ? obj.style.color="red";
? ? obj.style.backgroundColor="#ccc";
}
//定義"改變寬高"的函數(shù)
function changeWidth(){
? ? // var obj=document.getElementById("txt");
? ? obj.style.width="200px";
? ? obj.style.height="300px";
}
//定義"隱藏內(nèi)容"的函數(shù)
function changeHidden(){
? ? // var obj=document.getElementById("txt");
? ? obj.style.display="none";?
}
//定義"顯示內(nèi)容"的函數(shù)
function changeDisplay(){
? ? // var obj=document.getElementById("txt");
? ? obj.style.display="block";
}
//定義"取消設(shè)置"的函數(shù)
function changeSet(){
? ? // var obj=document.getElementById("txt");
? ? var con=confirm("是否確定取消設(shè)置");
? ? if(con==true){
? ? ? ? obj.removeAttribute('style');
? ? }else{
? ? ? ?document.write("您取消了設(shè)置");?
? ?}
}
</script>
2016-11-30
用你的代碼試了一下,其他沒(méi)問(wèn)題,最后少了一個(gè)</script>
2016-11-30
對(duì)啊,然后我對(duì)比了一下其他人的程序,我覺(jué)得沒(méi)有錯(cuò)的地方了,但是就是不行
2016-11-30
每個(gè)按鈕都沒(méi)反應(yīng)嗎