導航:首頁 > 編程語言 > js動態設置button的值

js動態設置button的值

發布時間:2025-07-05 03:49:19

js動態添加的DIV中的onclick事件簡單實例

最簡單的是這樣:<input type="button" onclick="alert(this.value)" value="我是 button" />動態添加onclick事件:
<input type="button" value="我是 button" id="bu"><script type="text/javascript">var bObj=document.getElementById("bu");bObj.onclick= objclick;function objclick(){alert(this.value)};</script>
如果使用匿名函數 function(){},則如下面所示:
<input type="button" value="我是 button" id="bu"><script type="text/javascript">var bObj=document.getElementById("bu");bObj.onclick=function(){alert(this.value)};</script>
上面的方法其實原理都一樣,都是定義 onclick 屬性的值。值得注意的是,如果多次定義 obj.onclick,例如:obj.onclick=method1; obj.onclick=method2; obj.onclick=method3,那麼只有最後一次的定義obj.onclick=method3才生效,前兩次的定義都給最後一次的覆蓋掉了。
再看 IE 中的 attachEvent:
<input type="button" value="我是拉登" id="bu"><script type="text/javascript">var bObj = document.getElementById("bu");bObj.attachEvent("onclick"method1);bObj.attachEvent("onclick"method2);bObj.attachEvent("onclick"method3);function method1(){alert("第一個alert")}function method2(){alert("第二個alert")}function method3(){alert("第三個alert")}</script>
執行順序是 method3 > method2 > method1 ,先進後出,與堆棧中的變數相似。需要注意的是attachEvent 中第一個參數是on開頭的,可以是 onclick/onmouseover/onfocus 等等
據說(未經確認驗證)在 IE 中使用 attachEvent 後最好再使用 detachEvent 來釋放內存
再看看 Firefox 中的的 addEventListener:
<input type="button" value="我是布希" id="bu"><script type="text/javascript">var bObj = document.getElementById("bu");bObj.addEventListener("click"method1,false);bObj.addEventListener("click"method2,false);bObj.addEventListener("click"method3,false);function method1(){alert("第一個alert")}function method2(){alert("第二個alert")}function method3(){alert("第三個alert")}</script>
可以看到,在 ff 中的執行順序是 method1 > method2 > method3 , 剛好與 IE 相反,先進先出。需要注意的是 addEventListener 有三個參數,第一個是不帶「on」的事件名稱,如 click/mouseover/focus等。

❷ JS如何控制button的位置

解決方法:

1、把button定義成絕對定位,position:absoulte的方式,然後設置left,top的方式進行位置控制

2、如果是節點移動,則可以通過dom刪除和增加的方式來調整位置

問題解決:

這里針對的是第二種情況,可以把對應的節點獲取後,刪除再插入到對應的節點後。

代碼示例:

<script>
functionmove(self){
varp=self.parentNode;//獲取當前節點的父節點
self.remove();//移除當前節點
p.appendChild(self);//父節點添加當前節點
}
</script>
</head>
<body>
<div>
<inputtype="button"id="button1"value="1"onclick="move(this)">
<inputtype="button"id="button2"value="2"/>
</div>
</body>

❸ button按鈕的屬性設置

button按鈕的屬性設置:
1、name:表示按鈕的名稱,通常作為按鈕標識進行使用。
2、type:表示按鈕類型,通常與表單一起聯用。reset:重置按鈕sumit:提交按鈕button:普通按鈕。
3、value:表示按鈕初始值,通常在js腳本中進行使用和修改。
4、disabled:表示禁用按鈕,使按鈕不能點擊END。
5、autoplay:當頁面載入時按鈕應當自動地獲得焦點。在實例中,我們會看到,第一次打開頁面的時候,發現按鈕出現了藍色邊框,就是所謂的焦點。
button的意思解釋如下:
button的中文釋義:
1、當詞性為名詞時,意為紐扣,扣子;按鈕;美徽章;不值錢的東西;按鈕廣告;按鈕層。
2、當詞性為動詞時,意為扣上;把…的紐扣扣上;用紐扣扣住;釘扣子。
3、當用作人名時,可翻譯為(Button)(英)巴頓。
button的讀法:button的英式發音為[?b?t(?)n];美式發音為[?b?t(?)n]。
短語搭配:
1、hot button引起強烈爭論的話題。
2、on the button准時,正好。
3、press the button按電鈕啟動。
4、radio button單選按鈕。
5、belly button(人的)肚臍。
雙語例句:
1、I pushed the button for the top floor.
我按了到頂層的按鈕。
2、This button is for adjusting the volume.
這個按鈕是調節音量的。
3、Anyone can sew on a button,including you.
任何人都能縫鈕扣,包括你。
4、Drago pressed a button and the door closed.
德拉戈按了一個按鈕,門關上了。
5、She pressed the button but nothing happened.
她按下按鈕,但什麼反應也沒有。
6、Adam pressed a button and waited for the lift.
亞當按了一個按鈕,然後等著乘坐電梯。
7、He ripped away a wire that led to the alarm button.
他把連接報警按鈕的電線扯掉了。
8、You may have inadvertently pressed the wrong button.
你也許無意中按錯了按鈕。
9、I sit down,thread a needle,snip off an old button.
我坐下來,穿好針,剪下了一粒舊鈕扣。
10、Mrs.Baylor strode to the lift and punched the button.
貝勒太太大步走到電梯前按了一下按鈕。

❹ 在JSP中如何獲取Button按鈕中的Value值

1、創建一來個名稱為 type_button 的html文件

❺ js給動態創建的按鈕添加動態事件

這是源JavaScript經典的閉包問題

你需要


document.getElementById('king'+i).onclick=function(i)
{
returnfunction()
{
document.getElementById('shipin').src=arr[i]
}
}(i)

❻ 在javascript中怎麼設置button的可點擊和不可點擊

、js中設置按鈕可點擊與不可點擊,默認是可點擊的

(1)設置按鈕不可版點擊權

document.getElementById("bt1").disabled=ture;

(2)設置按鈕可點擊

document.getElementById("bt1").disabled=false;

2、jq中設置按鈕可點擊與不可點擊,默認是可點擊的

(1)設置按鈕不可點擊

$("#bt1").attr("disabled",ture);

(1)設置按鈕可點擊

$("#bt1").attr("disabled",false);

3、標簽中設置按鈕不可點擊

在標簽中添加屬性disabled="true"。

閱讀全文

與js動態設置button的值相關的資料

熱點內容
為什麼工行app明細里查不到 瀏覽:293
jsp網站怎麼發布 瀏覽:101
vbnet獲取文件列表 瀏覽:883
fastcopy英文版教程 瀏覽:713
手動載入spring配置文件 瀏覽:77
www2h3com升級 瀏覽:17
仿列印文件夾 瀏覽:818
reactjs定時器 瀏覽:728
iphonese怎麼信任文件 瀏覽:816
配置文件選型 瀏覽:14
網路審計的模式有哪些 瀏覽:560
魅族微信角標 瀏覽:616
如何將手機數據存到電腦上 瀏覽:8
weblogic配置文件用戶名和密碼 瀏覽:693
10054錯誤代碼qq 瀏覽:873
qq音樂歌詞在哪個文件夾 瀏覽:699
團購app怎麼賺錢 瀏覽:616
c盤哪個文件夾能清理 瀏覽:80
優酷xl版本沒聲音 瀏覽:76
ps如轉化為尺量文件 瀏覽:767

友情鏈接