我有這樣的HTML代碼:如何防止按鈕在標籤控件內單擊?
<label style="padding: 0px 0px!important; text-align:center">
<span style="color: gray">Some Text</span>
<button onclick='alert("Hello!")' style="cursor: pointer;">
<i class="glyphicon glyphicon-pushpin btn-lg" aria-hidden="true"></i> </button>
</label>
這裏是JSFiddle。
在標籤控件中,我聲明button.Button是在單擊標籤中的任何區域時單擊的。如何僅在單擊按鈕時單擊它才能使按鈕自行點擊?
如果您需要HTML原樣,你只能防止點擊按鈕與JS ... 例如在button.click上添加一個監聽器,在你的點擊事件中檢查event.currentTarget,如果它沒有按鈕 - >然後preventDefault():)否則看看其他答案;) – MarcelD